Not sure if I got you correct, but you have to use QThread for that.
Not sure if I got you correct, but you have to use QThread for that.
hakermania (14th January 2011)
You dont't have to use threads.
Do this:
instead of
hakermania (15th January 2011)
.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 :/
When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.
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
Qt Code:
dlg->setRange( 0, 0 );To copy to clipboard, switch view to plain text mode
I wish my English writing wasn't horrible![]()
hakermania (22nd January 2011)
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.
When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.
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..show(); does move on with the following code but the program stucks (without displaying the Msgbox)
consider the following examples:
1)
2)
3)
Qt Code:
QMessageBox box; box.show(); qApp->processEvents(); while(1);To copy to clipboard, switch view to plain text mode
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.
Probably your code is inside a function, and msgBox gets out of scope, use a pointer:
Qt Code:
msgBox->setText("Please wait to connect to the server."); msgBox->setWindowTitle("Checking for update."); msgBox->setWindowModality(Qt::NonModal); msgBox->show();To copy to clipboard, switch view to plain text mode
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.
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
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:
Qt Code:
msgBox->setAttribute(Qt::WA_DeleteOnClose);To copy to clipboard, switch view to plain text mode
Hey, thank you all. It finally worked. This is what I did:
Thank you allQt Code:
//here button declarations msgBox1->setWindowModality(Qt::NonModal); msgBox1->show();To copy to clipboard, switch view to plain text mode
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?
Last edited by hakermania; 23rd January 2011 at 11:39.
When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.
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....
When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.
Bookmarks