Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. sleep
    Log in to post
    • All categories
    • D

      Unsolved I want to generate random number between the 0 to 1. with the interval of 1 second in qt.
      General and Desktop • delay wait sleep • • dev_liya

      6
      0
      Votes
      6
      Posts
      209
      Views

      S

      @dev_liya said in I want to generate random number between the 0 to 1. with the interval of 1 second in qt.:

      but my requirement is to generate in infinite loop ad show in window.

      If you do an infinite loop then the event loop will not run. That means that setting the random_label or anything like that will not show on the screen as the slots cannot be handled: your infinite loop will block the event loop. The effect is that you have a frozen application. So, trust @JonB.

      As per your request: to wait for one second and block everything (you have been warned!): use QThread::sleep(1);

    • T

      Solved Setting timeout for QLabel-Text without Signals&Sots
      General and Desktop • sleep timeout • • TUStudi

      3
      0
      Votes
      3
      Posts
      307
      Views

      T

      @JonB Thank you!

    • S

      Solved How to add rows automatically with sleep?
      General and Desktop • tableview qthread sleep • • SoleyRan

      3
      0
      Votes
      3
      Posts
      366
      Views

      S

      @Christian-Ehrlicher Thank you very much! It solved my problem perfectly :)

    • M

      Prevent Sleep on OSX and stand by on Windows
      General and Desktop • standy sleep • • mattewre

      2
      0
      Votes
      2
      Posts
      1365
      Views

      sierdzio

      Yes, you need to use native APIs to achieve that goal.

    • S

      In my Qt Multi-threaded program, moveToThread() & QCoreApplication::postEvent() dose work only msleep(1) is followed
      General and Desktop • postevent multi-thread sleep movetothread • • sinjohr

      2
      0
      Votes
      2
      Posts
      1105
      Views

      T

      @sinjohr I think this things happen. Working with threads is not always a cool path.

      According to the documentation, a QEvent::ThreadChange event is sent to the object just before the thread affinity is changed.

      You can try to handle the event.

      Another option is using the overloaded method

      void QCoreApplication::postEvent(QObject * receiver, QEvent * event, int priority)

      and use Qt::LowEventPriority.