Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Splashimage freezed by std::chrono
Forum Updated to NodeBB v4.3 + New Features

Splashimage freezed by std::chrono

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 293 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    U7Development
    wrote on last edited by U7Development
    #1

    Hi !
    I have created an imagen to be displayed as QSplashScreen, the idea is show this image, wait 5 seconds and close it..

    Method 0:

    QSplashScreen _qs();
    _qs.setPixmap(QPixmap(":imgs/res/iss.png"));
    _qs.show();
    
    //wait 5 seconds
    const std::chrono::steady_clock::time_point ini = std::chrono::steady_clock::now();
    unsigned short t {0};
    
    while (t != 5){
         auto actual = std::chrono::steady_clock::now();
         t = std::chrono::duration_cast<std::chrono::seconds>(actual - ini).count();
    }
    _qs.close();
    

    Problem is that auto actual variable is freezing the _qs.show() call and I see no image on the screen... Maybe std::chrono uses threads somehow and current thread is sleeping.

    If i comment the while loop, then splash shows successfuly (i need to comment _qs.close() too to appreciate it..

    Method 1:

    _qs.show();
    int ini = QTime::currentTime().second(); //current second
    int fin = ini + 5;  //5 seconds limit
    int t {0}; //second to elapse
    
    do{
        t = QTime::currentTime().second(); //seconds elapsed
    } while (t < fin);
    
    _qs.close();
    

    There is a method 2 using a second thread and sleep this second thread, but same happens. Is there any way to fix it.. or use another way to acchieve?...

    Thanks.

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      yes...you are doing a while loop until t==5 in the main event loop thread, so no events are being processed during that interval. The incorrect "fix" is to call the event processor method inside the loop. The correct fix is to show() the window, then use a QTimer as a countdown and hide() the window on timer expiration.

      U 1 Reply Last reply
      4
      • Kent-DorfmanK Kent-Dorfman

        yes...you are doing a while loop until t==5 in the main event loop thread, so no events are being processed during that interval. The incorrect "fix" is to call the event processor method inside the loop. The correct fix is to show() the window, then use a QTimer as a countdown and hide() the window on timer expiration.

        U Offline
        U Offline
        U7Development
        wrote on last edited by U7Development
        #3

        @Kent-Dorfman

        Yes that has sense.. just solved it with QTimer::singleShot :

        QTimer::singleShot(5000, nullptr, [&](){ _qs.close(); w.show(); });
        

        Thanks for reply..

        1 Reply Last reply
        2
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          if solved then please mark as solved. Thanks.

          Another option is to subclass QDialog as a splash screen and exec_() the dialog.

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved