Results 1 to 6 of 6

Thread: QMessageBox question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default QMessageBox question

    Hi I'm encountering a problem with QMessageBox. I'm using Qt 4.3.3 here.
    I'm trying to dismiss a QMessageBox using a handle, not by user pressing the button. So say for example, I have a QMessageBox mb1 present, and power supply is plugged in, I want to dismiss mb1 (stop the exec() command) and show another QMessageBox mb2. I can easily do the dismiss by using a QMessageBox *handle = &mb1 and do handle->accept(). The problem is that I want to put a log message immediately either after mb1 is dismissed by the system or by the user. The exec() is blocked if 2 messageboxes are present. This sounds complicated so I'll provide my sudo code in below:

    Qt Code:
    1. void showMessageBox(QMessageBox **handle, QString& title)
    2. {
    3. QMessageBox mb = new QMessageBox(title, textBody, QMessageBox::Warning, QMessageBox::Ok);
    4. *handle = &mb;
    5. <Some message box format settings here>
    6. exec();
    7. printf("%s finished\n", title);
    8. if (handle != NULL)
    9. *handle = NULL;
    10. }
    11.  
    12. void main(void)
    13. {
    14. showMessageBox(&mb1, "mb1"); //call exec() 1st time
    15. if (power_supply_in)
    16. {
    17. mb1->accept(); //mb1 disappears on the screen
    18. printf("mb1 dismissed by system\n");
    19. showMessageBox(&mb2, "mb2"); //call exec() 2nd time
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    You will think that when you do the mb1->accept(), the first exec() is terminated. What I expected to see is:
    mb1 finished // when you do mb1->accept();
    mb1 dismissed by system // when you do printf("messagebox dismissed by system\n");
    mb2 finished //when the user press the "Ok" button on mb2

    However, what I saw was:
    mb1 dismissed by system //when you do printf("messagebox dismissed by system\n");
    mb2 finished //when the user press the "Ok" button on mb2, this is jumping out of the 2nd exec() command
    mb1 finished //the program is jumping out of the 1st exec() command

    Seems like the program is stuck in the exec() if there are multiple QMessageBox in action. Can anyone explain why and how to get my expected results? Maybe there's an alternative of using mb1->accept()?

    I don't know whether I explained the question well. Please feel free to ask if I did too bad.. Thanks in advance!
    Last edited by shijiaguo; 21st May 2013 at 19:05.

  2. #2
    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: QMessageBox question

    Connect to the accepted() signal from the dialog.
    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.


Similar Threads

  1. QMessageBox
    By sonuani in forum Qt Programming
    Replies: 13
    Last Post: 2nd September 2009, 17:56
  2. QMessageBox
    By sonuani in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2008, 08:27
  3. Re: Help on QMessageBox
    By arunvv in forum Newbie
    Replies: 2
    Last Post: 25th March 2008, 23:45
  4. how to use tr() for QMessageBox?
    By gfunk in forum Qt Programming
    Replies: 4
    Last Post: 17th November 2007, 11:30
  5. QMessageBox::information box question
    By bruccutler in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2007, 17:30

Tags for this Thread

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.