Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Timer not working

    Mobile and Embedded
    5
    5
    1225
    Loading More Posts
    • 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.
    • R
      Rashmi last edited by

      Hello,

      I am using qtimer having 500 ms time value in my project.
      While performing file sorting operation,I observed that timer expired event not generated.
      It means timer slot get blocked till file operation complete.

      I will appreciate your quick response.
      Thanks.

      jsulm kshegunov 2 Replies Last reply Reply Quote 0
      • m.sue
        m.sue last edited by

        Hi,
        how did you start the sorting operation? The timer fires the execution of a slot. If the file sorting is done in another already running slot, the timer slot will execute after the file sorting is finished as all slots work one after the other: its a message queue, after all.
        You may need to do the file sorting in another thread to make the timer slot run in parallel.
        -Michael.

        1 Reply Last reply Reply Quote 2
        • kd_wala
          kd_wala last edited by kd_wala

          is file sorting operation running on main thread? is your timer you create & start on main thread? document say: timer must run on thread that have event loop.

          1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @Rashmi last edited by

            @Rashmi Most probably your sorting operation is lasting for long time and blocks the event loop :-)
            For example this loop will block event loop until finished:

            while(SOME_CONDITION) {
            
            }
            

            As long as the event loop is blocked your slot will not be executed.
            To avoid such problems you should avoid blocking operations in Qt (actually in all event-driven frameworks). If you cannot avoid them then execute them in a different thread.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 3
            • kshegunov
              kshegunov Moderators @Rashmi last edited by

              @jsulm said in Timer not working:

              As long as the event loop is blocked your slot will not be executed.

              Even something more, you'll get a single timer event after the whole interval. As explained in the docs:

              All timer types may time out later than expected if the system is busy or unable to provide the requested accuracy. In such a case of timeout overrun, Qt will emit activated() only once, even if multiple timeouts have expired, and then will resume the original interval.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply Reply Quote 2
              • First post
                Last post