Results 1 to 19 of 19

Thread: help with connect() without using QT creator

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    86
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    10
    Thanked 6 Times in 4 Posts

    Default Re: help with connect() without using QT creator

    Quote Originally Posted by wenn32 View Post
    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QLineEdit>
    4.  
    5. class NewSlot : public QWidget
    6. {
    7. Q_OBJECT
    8.  
    9. private slots:
    10. void open()
    11. {
    12. /* code to write to a file */
    13. // i know this part.
    14. }
    15. };
    16.  
    17.  
    18.  
    19. int main(int argc, char* argv[])
    20. {
    21. QApplication app(argc, argv);
    22. QWidget window;
    23. QLineEdit password("",&window);
    24.  
    25.  
    26. password.move(480,750);
    27. password.resize(370,30);
    28. password.setEchoMode(QLineEdit::Password);
    29. window.setWindowState(Qt::WindowFullScreen);
    30.  
    31.  
    32. QObject::connect(&password,SIGNAL(returnPressed()),&password,SLOT(write_to_file()));
    33. window.show();
    34. return app.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

    ok can i normally create a object of the class NewSlot and call in connect() and by the way how do i get the data of the password(QLineedit) field


    Thank you very much for helping me!

    Why not making your class the one which holds the password LineEdit, instead of the QWidget object ??
    this will give your slot easy access to get the text

  2. #2
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator

    Quote Originally Posted by ahmdsd_ostora View Post
    Why not making your class the one which holds the password LineEdit, instead of the QWidget object ??
    this will give your slot easy access to get the text
    now i really need help please!

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: help with connect() without using QT creator

    Quote Originally Posted by wenn32 View Post
    now i really need help please!
    May I ask you a question befor: Are you familiar with C++ or is it also new to you?

  4. #4
    Join Date
    Jun 2010
    Posts
    86
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    10
    Thanked 6 Times in 4 Posts

    Default Re: help with connect() without using QT creator

    Quote Originally Posted by wenn32 View Post
    now i really need help please!

    it's easier than you imagine:

    Qt Code:
    1. class MyScreen: public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. private:
    6. QLineEdit* password;
    7.  
    8. private slots:
    9. void write_to_file()
    10. {
    11. QString text = password->text();
    12. // write it to your file
    13. }
    14.  
    15. public:
    16. MyScreen()
    17. {
    18. password = new QLineEdit("" , this);
    19.  
    20. password->move(480,750);
    21. password->resize(370,30);
    22. password->setEchoMode(QLineEdit::Password);
    23. setWindowState(Qt::WindowFullScreen);
    24.  
    25. connect( password,SIGNAL(returnPressed()), this ,SLOT(write_to_file())
    26. }
    27.  
    28.  
    29. };
    30.  
    31.  
    32. int main(int argc, char* argv[])
    33. {
    34.  
    35. QApplication app(argc, argv);
    36.  
    37. NewSlot window;
    38. window.show();
    39.  
    40. return app.exec();
    41.  
    42. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: help with connect() without using QT creator

    instead of using move and resize, you really should use layouts: http://doc.trolltech.com/4.6/layout.html

Similar Threads

  1. Replies: 16
    Last Post: 16th February 2010, 13:17
  2. How to connect?
    By starlon in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2009, 23:24
  3. Replies: 4
    Last Post: 10th November 2006, 15:38
  4. connect
    By mickey in forum Newbie
    Replies: 15
    Last Post: 2nd August 2006, 22:42
  5. many connect
    By mickey in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2006, 12:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.