Results 1 to 7 of 7

Thread: QWidget with a return value

  1. #1
    Join Date
    Nov 2011
    Posts
    17
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default QWidget with a return value

    Hi,


    is it possible to create a small QWidget with some QLineEdits, which returns the content of these QLineEdits after closing the QWidget?
    Or is a QDialog more suitable to implment this functionality?

    Thanks

    Micha

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWidget with a return value

    Hi,

    A QDialog is useful when you want the user to take a decision before continuing a process. For example, ask for an answer before deleting a file. If this is the case, use QDialog.

    Carlos.

  3. #3
    Join Date
    Nov 2011
    Posts
    17
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QWidget with a return value

    Ok, then I should use a QWidget, because the user shall enter some values in QLineEdits and after closing the widget these values should be available in the parent window.

  4. #4
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWidget with a return value

    That depends. You can call QDialog with exec() so it appears as modal (the user cannot interact with other windows (including the parent) until it close the dialog). If the user can interact with the parent while the window with edits is on the screen then you can use a QDialog but calling show() or a QWidget.

  5. #5
    Join Date
    Nov 2011
    Posts
    17
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QWidget with a return value

    OK, if I would use QDialog with the exec function. How can I return the values from the QLineEdits to the parent widget?

  6. #6
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWidget with a return value

    ok You create a C++ class based on QDialog. Using QT designer for example. Say you called it myDialogWithEdits.

    This class has in its ui the edits. Because the ui is private you need to create a public function to get the value from the edits. Lets call it getValueOfEditOne().

    in the .h
    Qt Code:
    1. public:
    2. QString getValueOfEditOne();
    To copy to clipboard, switch view to plain text mode 

    in the .cpp
    Qt Code:
    1. myDialogWithEdits::getValueOfEditOne()
    2. {
    3. return ui->edit1->text();
    4. {
    To copy to clipboard, switch view to plain text mode 

    The in the parent you do:
    Qt Code:
    1. QDialog myDialogWithEdits;
    2. myDialogWithEdits.exec(); //This will call modal and wait until its closes
    3.  
    4. //This will be executed after it closes
    5. ui->edit1->setText(myDialogWithEdits.getValueOfEditOne());
    To copy to clipboard, switch view to plain text mode 

    Carlos

  7. The following user says thank you to qlands for this useful post:

    klenze (23rd November 2011)

  8. #7
    Join Date
    Nov 2011
    Posts
    17
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QWidget with a return value

    Thanks, it works perfect!

Similar Threads

  1. Replies: 1
    Last Post: 30th October 2010, 12:28
  2. Replies: 1
    Last Post: 16th September 2010, 15:57
  3. Replies: 1
    Last Post: 12th April 2010, 12:55
  4. Replies: 3
    Last Post: 1st April 2010, 23:56
  5. Replies: 1
    Last Post: 2nd May 2006, 21:11

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.