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:
void showMessageBox
(QMessageBox **handle, QString
& title
) {
*handle = &mb;
<Some message box format settings here>
exec();
printf("%s finished\n", title);
if (handle != NULL)
*handle = NULL;
}
void main(void)
{
showMessageBox(&mb1, "mb1"); //call exec() 1st time
if (power_supply_in)
{
mb1->accept(); //mb1 disappears on the screen
printf("mb1 dismissed by system\n");
showMessageBox(&mb2, "mb2"); //call exec() 2nd time
}
}
void showMessageBox(QMessageBox **handle, QString& title)
{
QMessageBox mb = new QMessageBox(title, textBody, QMessageBox::Warning, QMessageBox::Ok);
*handle = &mb;
<Some message box format settings here>
exec();
printf("%s finished\n", title);
if (handle != NULL)
*handle = NULL;
}
void main(void)
{
QMessageBox *mb1;
showMessageBox(&mb1, "mb1"); //call exec() 1st time
if (power_supply_in)
{
mb1->accept(); //mb1 disappears on the screen
printf("mb1 dismissed by system\n");
QMessageBox *mb2;
showMessageBox(&mb2, "mb2"); //call exec() 2nd time
}
}
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!
Bookmarks