Results 1 to 4 of 4

Thread: Problem pausing the main thread

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem pausing the main thread

    Hi to all,
    I would pause the main thread for 2-3 sec and then exit from the application but I can not find a solution.

    In my case when application starts a status dialog appears showing some result and then the main window is shown. There is a case where I would wait a couple of seconds ( to give to the user the time to read ) and then exit completely from the application. This is the code I wrote:

    Qt Code:
    1. void CertiIrisApp::init() //CertiIrisApp is the main application derived class
    2. {
    3. start = new StartDlg(0); // start is a dialog showing some initialization results
    4. start->show();
    5. start->print(QString("> Welcome to CertiIris")); //print prints a message
    6. processEvents();
    7. start->print(QString("> Checking for Iris scanner..."));
    8. if (checkIrisScanner())
    9. {
    10. start->print(QString("> Correct Iris scanner connected."));
    11. processEvents();
    12. }
    13. else
    14. {
    15. QString msg = "> An incorrect iris scanner has been connected, contact author.";
    16. start->print(msg);
    17. processEvents();
    18. Sleep(1); // I would wait to give the time to read
    19. QCoreApplication::exit(1); //and then exit
    20. }
    21.  
    22. if ( connectToDB() == true )
    23. {
    24. QString str = "> " + QCoreApplication::applicationName() + " is successfully connected to the IrisServer.";
    25. start->print(str);
    26. processEvents();
    27. onLoadDBRecords();
    28. }
    29. else
    30. {
    31. QString str = "> " + QCoreApplication::applicationName() + " could not connected to the IrisServer.";
    32. start->print(str);
    33. processEvents();
    34. }
    35.  
    36. start->hide(); // hide the dialog
    37. delete start; // and delete it
    38. m_mainWnd->show(); // here I show the main window
    39. return;
    40. }
    To copy to clipboard, switch view to plain text mode 
    The problem of my code is that the program flow doesn't wait at the Sleep call and follow showing the next message.
    Where is my mistake?

    Regards,
    Franco
    Franco Amato

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Problem pausing the main thread

    Are you sure your Sleep() isn't a Windows API call in which case it sleeps only for one millisecond?

  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem pausing the main thread

    Quote Originally Posted by mvuori View Post
    Are you sure your Sleep() isn't a Windows API call in which case it sleeps only for one millisecond?
    Sorry I did a mistake writing the post.
    The right code is Sleep(2000) but I don't know why I see the messages following the call to QCoreApplication::exit(1);
    Before exiting the application the program execute some instructions that it shouldn't execute
    Franco Amato

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem pausing the main thread

    Is reading the documentation so hard?
    Note that unlike the C library function of the same name, this function does return to the caller -- it is event processing that stops.
    So simple do:
    Qt Code:
    1. return;
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Pausing a thread while waiting that phonon play a sound file
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2011, 21:41
  2. Replies: 5
    Last Post: 22nd February 2011, 21:21
  3. Replies: 7
    Last Post: 6th November 2010, 08:32
  4. Replies: 9
    Last Post: 28th November 2009, 20:31
  5. Replies: 16
    Last Post: 7th October 2009, 08:17

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.