Results 1 to 4 of 4

Thread: QDialog.exec() exiting without calling QDialog::accept()

  1. #1
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QDialog.exec() exiting without calling QDialog::accept()

    Hi,

    In my code I have a dialog box which has an OK button. I show it by calling diag.exec(). The slot on the OK button has the following code:

    Qt Code:
    1. void SLOTOkBtn()
    2. {
    3. QList<QTreeWidgetItem *> selectedItems = ui.m_PackageList->selectedItems();
    4.  
    5. if ( selectedItems.isEmpty() )
    6. {
    7. return;
    8. }
    9. else
    10. {
    11. // Provides you with the first selection
    12. m_Package = selectedItems.first()->text( 0 ).toAscii().data();
    13. QDialog::accept();
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    Now if I hit OK and no items are selected, it gets to return;, which is what i would expect - however, rather than staying in exec(), it is closing the dialog box, and the test on the return code from diag.exec() give QDialog::Accepted, even though QDialog::Accept() has not been called.

    Any ideas what i am doing wrong?

    David

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog.exec() exiting without calling QDialog::accept()

    put some debug statements in both if and else block. See what isEmpty() returns.

  3. #3
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog.exec() exiting without calling QDialog::accept()

    I've put debuging in and also stepped through the code. That's how I know it's hitting the:

    return;

    and not:

    QDialog::accept();

    I just can't work out why the dialog box goes when QDialog::accept() has not been called.

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog.exec() exiting without calling QDialog::accept()

    provide a minimal compilable program reproducing the problem. there is no way to help without that.

Similar Threads

  1. QDialog problem with exec()
    By nomadscarecrow in forum Qt Programming
    Replies: 3
    Last Post: 23rd April 2010, 19:40
  2. exec() not blocking, derived QDialog, Qt 4.4.3
    By wdezell in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2009, 19:56
  3. problem with show/exec of Qdialog
    By dudedude in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 12:20
  4. QDialog::exec : Recursive call detected.
    By node_ex in forum Qt Programming
    Replies: 4
    Last Post: 29th June 2008, 18:50
  5. QDialog: show() and exec() together in constructor?
    By Teuniz in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2007, 12:43

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.