Results 1 to 14 of 14

Thread: Just launch QMessageBox and then continue with following code?

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Just launch QMessageBox and then continue with following code?

    Hello.

    This is the code:
    Qt Code:
    1. QMessageBox msgBox;
    2. msgBox.setText("Please wait to connect to the server.");
    3. msgBox.setWindowTitle("Checking for update.");
    4. msgBox.exec();
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. if(msgBox.isVisible())
    2. msgBox.close();
    To copy to clipboard, switch view to plain text mode 
    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)
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Just launch QMessageBox and then continue with following code?

    Did you try show()?
    Better yet, use setWindowModality().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    hakermania (14th January 2011)

  4. #3
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:
    Qt Code:
    1. QMessageBox msgBox;
    2. msgBox.setText("Please wait to connect to the server.");
    3. msgBox.setWindowTitle("Checking for update.");
    4. msgBox.setWindowModality(Qt::WindowModal);
    5. msgBox.exec();
    To copy to clipboard, switch view to plain text mode 
    but it doesn't work. It works exactly like the .exec(); option without setting any modality.

    Can you help a bit? Thanks a lot!
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  5. #4
    Join Date
    Jul 2010
    Posts
    30
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  6. The following user says thank you to Diath for this useful post:

    hakermania (14th January 2011)

  7. #5
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Just launch QMessageBox and then continue with following code?

    Quote Originally Posted by Diath View Post
    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?
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  8. #6
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Just launch QMessageBox and then continue with following code?

    You dont't have to use threads.

    Do this:
    Qt Code:
    1. msgBox.show();
    To copy to clipboard, switch view to plain text mode 

    instead of
    Qt Code:
    1. msgBox.exec();
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to boudie for this useful post:

    hakermania (15th January 2011)

  10. #7
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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 :/
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  11. #8
    Join Date
    Jul 2010
    Posts
    30
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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
    Qt Code:
    1. dlg->setRange( 0, 0 );
    To copy to clipboard, switch view to plain text mode 

    I wish my English writing wasn't horrible

  12. The following user says thank you to .:saeed:. for this useful post:

    hakermania (22nd January 2011)

  13. #9
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  14. #10
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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)
    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)
    Qt Code:
    1. box.show();
    2. while(1);
    To copy to clipboard, switch view to plain text mode 
    2)
    Qt Code:
    1. box.exec();
    2. while(1);
    To copy to clipboard, switch view to plain text mode 
    3)
    Qt Code:
    1. box.show();
    2. qApp->processEvents();
    3. 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.

  15. #11
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default 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:

    Qt Code:
    1. QMessageBox *msgBox = new QMessageBox;
    2. msgBox->setText("Please wait to connect to the server.");
    3. msgBox->setWindowTitle("Checking for update.");
    4. msgBox->setWindowModality(Qt::NonModal);
    5. 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

  16. #12
    Join Date
    Jan 2011
    Location
    Netherlands
    Posts
    17
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. msgBox->setAttribute(Qt::WA_DeleteOnClose);
    To copy to clipboard, switch view to plain text mode 

  17. #13
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Talking Re: Just launch QMessageBox and then continue with following code?

    Hey, thank you all. It finally worked. This is what I did:
    Qt Code:
    1. QMessageBox *msgBox1 = new QMessageBox;
    2. //here button declarations
    3. msgBox1->setWindowModality(Qt::NonModal);
    4. QCoreApplication::processEvents();
    5. msgBox1->show();
    6. QCoreApplication::processEvents();
    To copy to clipboard, switch view to plain text mode 
    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?
    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.

  18. #14
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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....
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

Similar Threads

  1. Replies: 6
    Last Post: 26th April 2010, 16:47
  2. I cannot launch my app!
    By MIH1406 in forum Qt Tools
    Replies: 9
    Last Post: 26th October 2009, 11:53
  3. Qt nmake error - can I continue with build?
    By QPlace in forum Installation and Deployment
    Replies: 0
    Last Post: 7th April 2009, 18:18
  4. launch app
    By damien in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2009, 19:42
  5. How to wait 2 seconds before continue
    By raphaelf in forum Newbie
    Replies: 3
    Last Post: 25th June 2008, 14:36

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
  •  
Qt is a trademark of The Qt Company.