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. QTimer with zero timeout not work
Forum Updated to NodeBB v4.3 + New Features

QTimer with zero timeout not work

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 3.9k Views 3 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.
  • C Offline
    C Offline
    cengzm
    wrote on last edited by
    #1

    QTimer with zero timeout works different from what is described in doc. If the QTimer is in the main thread, the GUI interface will freeze. If I new a QTimer in an object affiliated to another thread and set the timeout to zero, It would work fine.

    K 1 Reply Last reply
    0
    • C cengzm

      QTimer with zero timeout works different from what is described in doc. If the QTimer is in the main thread, the GUI interface will freeze. If I new a QTimer in an object affiliated to another thread and set the timeout to zero, It would work fine.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @cengzm
      Hi and welcome to devnet

      You may want tocheck with Qt bug tracker JIRA if there is already a bug reported. If it is not reproted you can enter it there. This forum is not tracked for bug reports and their solution. Therefore, bugs reported here may be noticed by some people, but they almost certainly get lost.

      Vote the answer(s) that helped you to solve your issue(s)

      C 1 Reply Last reply
      0
      • C Offline
        C Offline
        cengzm
        wrote on last edited by
        #3

        My computer is armed with 8 cpu cores and if I use the QTimer in a thread other than the GUI thread and set the timeout to be zero, the CPU consumption of my program would be about 13%, and one of the cpu cores is never idle. Why the time slice schedule policy not work here?

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          If you do something like

          void MainWindow::ProcessText() {
            qDebug() << "test";
            // GIGA FOR LOOP 
          }
          
          void MainWindow::on_pushButton_released() {
            QTimer* timer = new QTimer(this);
            connect(timer, SIGNAL(timeout()), this, SLOT(ProcessText()));
            timer->start();
          }
          

          and ProcessText() takes a long time,it will block GUI thread.
          "ProcessText()" must do the task step wise as not to block.

          C 1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            If you do something like

            void MainWindow::ProcessText() {
              qDebug() << "test";
              // GIGA FOR LOOP 
            }
            
            void MainWindow::on_pushButton_released() {
              QTimer* timer = new QTimer(this);
              connect(timer, SIGNAL(timeout()), this, SLOT(ProcessText()));
              timer->start();
            }
            

            and ProcessText() takes a long time,it will block GUI thread.
            "ProcessText()" must do the task step wise as not to block.

            C Offline
            C Offline
            cengzm
            wrote on last edited by
            #5

            @mrjj
            I have tried to set the slot to be an empty function(do nothing at all) and still get freezed. And my desktop will freeze too, I must use Ctl+Shift+Esc to call out the task manager to end the process to continue.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Ok that sounds odd.
              If you create a new default GUI project and use the code above,
              does it still do i t?
              Here is prints tons of "test" but nothing lags.
              If you can reproduce it in a minimal sample, you might found bug.
              ps. Windows 7, 64bit, mingw compiler. qt 5.5

              C 1 Reply Last reply
              0
              • mrjjM mrjj

                Ok that sounds odd.
                If you create a new default GUI project and use the code above,
                does it still do i t?
                Here is prints tons of "test" but nothing lags.
                If you can reproduce it in a minimal sample, you might found bug.
                ps. Windows 7, 64bit, mingw compiler. qt 5.5

                C Offline
                C Offline
                cengzm
                wrote on last edited by
                #7

                @mrjj
                MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                {
                QTimer * timer = new QTimer(this);
                QLineEdit * le = new QLineEdit(this);
                connect(timer,SIGNAL(timeout()),this,SLOT(test()));
                timer->start();
                }

                MainWindow::~MainWindow()
                {

                }

                void MainWindow::test()
                {
                static int i=0;
                if(0 == i%1000)
                qDebug()<<"test";
                i++;
                }
                test result is:
                1, I can see the "test" output at the console
                2, I can input in the lineedit, minimum and maximum the main window
                3, once I try to move the main window, the system gets freezed.
                ps. windows 7, 64bit, msvc2012 compiler, qt 5.0.2

                1 Reply Last reply
                0
                • K koahnig

                  @cengzm
                  Hi and welcome to devnet

                  You may want tocheck with Qt bug tracker JIRA if there is already a bug reported. If it is not reproted you can enter it there. This forum is not tracked for bug reports and their solution. Therefore, bugs reported here may be noticed by some people, but they almost certainly get lost.

                  C Offline
                  C Offline
                  cengzm
                  wrote on last edited by
                  #8

                  @koahnig
                  Thanks and I have searched the bug report list and nothing related is found. I've reported the issue as QTBUG-7618. It seems I should try another release for luck...

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @cengzm said:

                    qt 5.0.2

                    If possible upgrade to newer Qt and see of problem exists.

                    I see nothing wrong and your code works fine here even when moving window.

                    Could be a bug, or something local.

                    C 2 Replies Last reply
                    0
                    • mrjjM mrjj

                      @cengzm said:

                      qt 5.0.2

                      If possible upgrade to newer Qt and see of problem exists.

                      I see nothing wrong and your code works fine here even when moving window.

                      Could be a bug, or something local.

                      C Offline
                      C Offline
                      cengzm
                      wrote on last edited by
                      #10

                      @mrjj
                      Thanks for you response very much. I would try a newer release.

                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @cengzm said:

                        qt 5.0.2

                        If possible upgrade to newer Qt and see of problem exists.

                        I see nothing wrong and your code works fine here even when moving window.

                        Could be a bug, or something local.

                        C Offline
                        C Offline
                        cengzm
                        wrote on last edited by
                        #11

                        @mrjj
                        I setup Qt5.5.1 and test the same code. Everyting works fine~

                        mrjjM JKSHJ 2 Replies Last reply
                        1
                        • C cengzm

                          @mrjj
                          I setup Qt5.5.1 and test the same code. Everyting works fine~

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @cengzm
                          So odd bug in 5.0.2 ?

                          1 Reply Last reply
                          0
                          • C cengzm

                            @mrjj
                            I setup Qt5.5.1 and test the same code. Everyting works fine~

                            JKSHJ Offline
                            JKSHJ Offline
                            JKSH
                            Moderators
                            wrote on last edited by
                            #13

                            @cengzm said:

                            I setup Qt5.5.1 and test the same code. Everyting works fine~

                            Good news!

                            Please update your bug report with this info. Qt 5.0.2 is very old.

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            1 Reply Last reply
                            0

                            • Login

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