Results 1 to 5 of 5

Thread: How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog

  1. #1
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog

    The title pretty much states it all.

    I have a modeless dialog in my application, and within it is a QLineEdit object and a QPushButton. How can I emit the value of the QLineEdit object (i.e. the user input) to the rest of the application when the user pressed the QPushButton (i.e. "Ok")?

    If it were a modal dialog, then it'd simply be the return value of the calling function, but being modeless... any suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog

    Simply emit a signal from the slot connected to the Ok button.

    Then in your program connect a slot to this signal.

  3. #3
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog

    Please excuse my ignorance, but I'm not quite following. To keep things simple, here's the code:
    Qt Code:
    1. bool MyCanvas::HorizonDialog()
    2. {
    3. QDialog* dlg = new QDialog(this);
    4. dlg->setAttribute(Qt::WA_DeleteOnClose);
    5. dlg->setWindowTitle("New Horizon");
    6. QHBoxLayout* layout = new QHBoxLayout;
    7. QPushButton* ok = new QPushButton("OK",dlg);
    8. ok->setDefault(true);
    9. connect(ok,SIGNAL(clicked()),dlg,SLOT(close()));
    10. connect(ok,SIGNAL(clicked()),this,SLOT(NewHorizon()));
    11. QPushButton* cancel = new QPushButton("Cancel",dlg);
    12. QLineEdit* text = new QLineEdit(dlg);
    13. layout->addWidget(text);
    14. layout->addWidget(ok);
    15. layout->addWidget(cancel);
    16. dlg->setLayout(layout);
    17. dlg->raise();
    18. dlg->show();
    19. return true;
    20. }
    To copy to clipboard, switch view to plain text mode 

    Are you suggesting placing a
    Qt Code:
    1. connect(ok,SIGNAL(clicked()), //.... I honestly don't know what to connect that signal to.
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog

    tbscope is suggesting to subclass QDialog, move most of the code from your HorizonDialog() method to its constructor and add a signal to the class. Besides the signal add a slot that will be connected to your ok button's clicked signal. From within that slot emit the dialog signal and make it carry the value you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    Wasabi (15th September 2010)

  6. #5
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog

    Ah, yes indeed, that would do the trick, wouldn't it?

Similar Threads

  1. Replies: 16
    Last Post: 8th April 2011, 16:56
  2. QFileDialog in modeless QDialog and mutex error
    By enno in forum Qt Programming
    Replies: 2
    Last Post: 7th April 2010, 20:49
  3. QDialog modeless problem
    By sgtbash in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2009, 19:03
  4. Replies: 3
    Last Post: 28th January 2007, 17:24

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.