Just launch QMessageBox and then continue with following code?
Hello.
This is the code:
Code:
msgBox.setText("Please wait to connect to the server.");
msgBox.setWindowTitle("Checking for update.");
msgBox.exec();
This executes the msgBox and waits for the user to click OK or [X] to the messagebox dialog. What I need is, after the .exec the program to continue with the following code (for instance to start checking for the update) and perform the check:
Code:
if(msgBox.isVisible())
msgBox.close();
before displaying another message letting the user know if there is or not update.
How can you just launch a MessageBox?
(for anybody familiar to bash scripting it is similar to the symbol '&' after calling an application)
Re: Just launch QMessageBox and then continue with following code?
Did you try show()?
Better yet, use setWindowModality().
Re: Just launch QMessageBox and then continue with following code?
Hello and thanks for the answer. Can you explain me a bit how setWindowModality works actually? I tried this:
Code:
msgBox.setText("Please wait to connect to the server.");
msgBox.setWindowTitle("Checking for update.");
msgBox.setWindowModality(Qt::WindowModal);
msgBox.exec();
but it doesn't work. It works exactly like the .exec(); option without setting any modality.
Can you help a bit? Thanks a lot!:)
Re: Just launch QMessageBox and then continue with following code?
Not sure if I got you correct, but you have to use QThread for that.
Re: Just launch QMessageBox and then continue with following code?
Quote:
Originally Posted by
Diath
Not sure if I got you correct, but you have to use QThread for that.
Hey, thx for the extra answer. Can you guide me a bit? :)
Re: Just launch QMessageBox and then continue with following code?
You dont't have to use threads.
Do this:
instead of
Re: Just launch QMessageBox and then continue with following code?
.show(); does move on with the following code but the program stucks (without displaying the Msgbox) till the call of .close(); which closes it and opens up another messagebox with .exec();
I am quite confused, I already have taken a lot of solution on this issue :/
Re: Just launch QMessageBox and then continue with following code?
I think QProgressDialog is the best choice for your request
Your sign is correct "When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples. "
but I think a newbie has to learn how to use Qt Assistant. So please read its complete def about QProgressDialog and ask your Questions,
But don't forget this note:
If you can't predict the progress of your situation , ( Like connecting to server ) you can use this code to change the behavior of your progress dialog
Code:
dlg->setRange( 0, 0 );
I wish my English writing wasn't horrible :p
Re: Just launch QMessageBox and then continue with following code?
Thanks. I am trying to create a new QDialog and have the progressbar there, but I have the same problem with the show and exec.
Re: Just launch QMessageBox and then continue with following code?
Quote:
.show(); does move on with the following code but the program stucks (without displaying the Msgbox)
The difference is that exec() shows the window and blocks untill it's closed, where show() just posts show event to widget and continues without blocking.
consider the following examples:
1)
Code:
box.show();
while(1);
2)
Code:
box.exec();
while(1);
3)
Code:
box.show();
qApp->processEvents();
while(1);
All of them will eventualy loop forever, but thats not important right now.
In 1) you probably wont see the message box at all, because the "show" event will not be delivered to message box, program enters while(1) loop and happily loops.
In 2) message box will be displayed and program will wait untill you'll close it or click the default "ok" button.
3) will render the box properly, but you will be unable to do anything, because the while(1) loop will start running.
Its because processing the events will show your message box before moving on.
I hope its clear enough.
Re: Just launch QMessageBox and then continue with following code?
Probably your code is inside a function, and msgBox gets out of scope, use a pointer:
Code:
msgBox->setText("Please wait to connect to the server.");
msgBox->setWindowTitle("Checking for update.");
msgBox->setWindowModality(Qt::NonModal);
msgBox->show();
Thsi code is just a example. The best option, probably, would be to declare msgBox inside of a class, for example, because if you keep calling this function, you will probably have a memory leak.
Re: Just launch QMessageBox and then continue with following code?
You won't have a memory leak if you set the attribute such that the object is deleted once the messagebox is closed. You can do this by setting:
Code:
msgBox->setAttribute(Qt::WA_DeleteOnClose);
Re: Just launch QMessageBox and then continue with following code?
Hey, thank you all. It finally worked. This is what I did:
Code:
//here button declarations
msgBox1->setWindowModality(Qt::NonModal);
msgBox1->show();
Thank you all :)
On last problem:
After this first "Please Wait" button, I want to close it and open the next one, which informs the user about update or not. The thing is, that when I call
if(msgbox->isEnabled())
msgbox->close();
it just deletes all the "widgets" of the msgBox and it let it empty. What should I call?
EDIT:
I was wrong, the msgBox when is shown IS EMPTY (nothing is shown, even if I have call setText() )
When another button is shown and I call msgbox->close(), the text is shown for 0.00001 secs and then it disappears, as it should...
What's wrong?
Re: Just launch QMessageBox and then continue with following code?
Well, I've placed everywhere qApp->processEvents(); and I have
msgBox1->setAttribute(Qt::WA_DeleteOnClose);
msgBox1->setWindowModality(Qt::NonModal);
but now, sometimes it does show up normally, sometimes it is too slow and it only updates when it is to close to show the next messagebox...Quite weird.... ANy other who want to help me a bit? I think I am close....