Results 1 to 10 of 10

Thread: Returning from Dialog

  1. #1
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    5
    Qt products
    Qt5

    Default Returning from Dialog

    Hi All,
    I am working with QT-4 on desktop applications,
    I have creted Child1 and Child 1 has child2, both are dilogs,
    my parent is mainwindow and both the childs are dialogs.
    when i close Child2, i am returning to parent instead of child 1.

    i have use event::accepted to process the data.
    What should be the method to accept the data from child2 dialog.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Returning from Dialog

    That description is way to confusing.

    You need at least post the two methods that create/execute the dialogs.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    5
    Qt products
    Qt5

    Default Re: Returning from Dialog

    I am using exec() method to show the dialog and checking the return status.

    main window has add_item button which has on click slot as
    connect( ui->add_contact, SIGNAL(clicked()), this, SLOT(addItem()) );

    The slot functiopn Add_Item is as follows
    void MainWindow::addItem()
    {
    MYDialog dlg( this );
    if( dlg.exec() == QDialog::Accepted )//for this we have used signal and slot of OK on dialog_window
    {
    ui->contact_list->addItem( dlg.name() + " -- " + dlg.number() );
    qDebug() << "entry accepted form dialog";
    }
    }


    the MYDialog has a lineedit which on return press event creates a numpad dialog.
    //in constructor of MYDialog
    connect( ui->num_Edit, SIGNAL( returnPressed () ) , this, SLOT( Accept_numer_thrKeypad() ));


    Accept_numer_thrKeypad this function creates/executes numpad.
    void Dialog::Accept_numer_thrKeypad( )
    {
    keypad numpad(this);

    QString number;
    number = this->number();
    numpad.setText(number);

    if( numpad.exec() == keypad::Accepted )
    {
    QString value;
    value = numpad.return_valueof_keypad();
    setNumber(value);
    }
    }

    Both the childs have accept() and reject() slots connected with the OK and Cancel button created on them.
    So when i press OK of numpad i am returning to MainWindow, but i expect i should return to its parent i.e. MYdialog object dlg.

  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: Returning from Dialog

    What do you mean by "returning to" main window?
    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. #5
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    5
    Qt products
    Qt5

    Default Re: Returning from Dialog

    Returning to main window means, after clicking OK/Cancel button on Child-2 dialog, the Main window appears, i am expecting to code such that after clicking OK/Cancel of Child-2 dialog, Child-1 dialog should be visible.

  6. #6
    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: Returning from Dialog

    Quote Originally Posted by SSqt5.2 View Post
    Returning to main window means, after clicking OK/Cancel button on Child-2 dialog, the Main window appears,
    Hmm... and what code makes it disappear? Do you call hide() anywhere?
    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.


  7. #7
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    5
    Qt products
    Qt5

    Default Re: Returning from Dialog

    In my code i have never called hide(), or Delete() for any dialog or widgets. the dialog disappears after event on OK/Cancel button.

  8. #8
    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: Returning from Dialog

    Quote Originally Posted by SSqt5.2 View Post
    In my code i have never called hide(), or Delete() for any dialog or widgets. the dialog disappears after event on OK/Cancel button.
    So how come when you launch a dialog, the main window disappears?

    Maybe it would be best if you provided a minimal compilable example reproducing the problem?

    This code seems to work fine:

    Qt Code:
    1. #include <QtWidgets>
    2.  
    3. class MainWindow : public QMainWindow {
    4. Q_OBJECT
    5. public:
    6. MainWindow() {
    7. QPushButton *pb = new QPushButton("Press");
    8. setCentralWidget(pb);
    9. connect(pb, SIGNAL(clicked()), this, SLOT(showDialog()));
    10.  
    11. }
    12. public slots:
    13. void showDialog() {
    14. QDialog dlg;
    15. QPushButton *pb = new QPushButton("Show another dialog");
    16. QVBoxLayout *l = new QVBoxLayout(&dlg);
    17. l->addWidget(pb);
    18. connect(pb, SIGNAL(clicked()), this, SLOT(showDialog2()));
    19. dlg.exec();
    20. }
    21. void showDialog2() {
    22. QDialog dlg;
    23. QPushButton *pb = new QPushButton("Close");
    24. QVBoxLayout *l = new QVBoxLayout(&dlg);
    25. l->addWidget(pb);
    26. connect(pb, SIGNAL(clicked()), &dlg, SLOT(accept()));
    27. dlg.exec();
    28. }
    29. };
    30.  
    31. #include "main.moc"
    32.  
    33. int main(int argc, char **argv) {
    34. QApplication app(argc, argv);
    35. MainWindow mw;
    36. mw.show();
    37. app.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 17th October 2014 at 13:25.
    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.


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

    SSqt5.2 (20th October 2014)

  10. #9
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    5
    Qt products
    Qt5

    Default Re: Returning from Dialog

    Thanks for reply.
    I tried this and find the error :: i was taking event on "QDialog" where it was supposed to be user_defined dialog(so, as Child-2 is also derived from QDialog, the event was passed to Child-1).

    Another error.
    If i have accept and reject slot for my-defined dialog,
    and i check the event as
    if (numpad.exec() == Keypad::Accepted )
    {
    }
    else if( numpad.exec() == Keypad::Rejected )
    {
    }

    i find that i need to specify two events before the dialog returns to parent (may be bcz, in one function i ma calling exec() twice). What is the way to return to parent window by accept or reject event only? (can i write switch case for event and if yes how?)

  11. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Returning from Dialog

    You are potentially running the dialog twice.
    If the first run does not return Keypad::Accepted, the second if condition will be evaluated which runs the dialog again.

    If your exec() can return more than two values, consider using a switch instead of multiple if/else-if

    Cheers,
    _

  12. The following user says thank you to anda_skoa for this useful post:

    SSqt5.2 (20th October 2014)

Similar Threads

  1. Replies: 2
    Last Post: 6th July 2011, 16:20
  2. Function returning a QHBoxLayout
    By aomegax in forum Newbie
    Replies: 5
    Last Post: 16th August 2010, 19:19
  3. Returning const &
    By frenk_castle in forum Newbie
    Replies: 2
    Last Post: 24th November 2009, 08:01
  4. returning a string
    By mickey in forum General Programming
    Replies: 2
    Last Post: 3rd February 2008, 20:41
  5. Replies: 3
    Last Post: 18th October 2007, 09:07

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.