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. Low performance, timer and label.
Forum Update on Monday, May 27th 2025

Low performance, timer and label.

Scheduled Pinned Locked Moved Unsolved General and Desktop
36 Posts 7 Posters 10.7k Views
  • 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.
  • L Offline
    L Offline
    Loc888
    wrote on last edited by
    #1

    Hi, i have some problems with QTimer, and label. I wanna create a simple stopwatch, but the time is highly delayed, it's around 15% different, so 30s is equal to 35s.

    Settext function is causing all the problems, and i need it to update the Ms label.

    I am having a lot of bugs with QT, and one of them is it, i have two stopwatches, and one of them was working almost good (Very small percent of delay,almost 0), and the second one, was almost 35% of delay, horrible score.... The second one, is working on the same simple function, and i made it (It's a copy, with different variable name's).

    I was trying to find the issue, why one of the timer, working with a copy of function, was doing that.
    What's funny? When i just deleted the old TabWidget, and created new one (In general, i dont change any settings), now these two timers have the same delay of around 7-10%. I have no idea what's going on, and i have enough.

    If you can do something, cuz i have some bugs with my Qt, sometimes when i delete some objects, then when i press one button, the application crash, and i need to delete, and rebuild the project (It doesn't work if i just press the rebuild button, i lose a lot of time before i notice that).

    Release version is a completely mess up, simple calculations are giving some totally unknown results, basicly 100% is broken, functions are giving stuff from nowhere.

    If i switch to debug version, everything works good. Just the timers still have that low performance.

    I dont know if i should download newer version, and what is causing these problems.

    J.HilkJ VRoninV 2 Replies Last reply
    0
    • L Loc888

      Hi, i have some problems with QTimer, and label. I wanna create a simple stopwatch, but the time is highly delayed, it's around 15% different, so 30s is equal to 35s.

      Settext function is causing all the problems, and i need it to update the Ms label.

      I am having a lot of bugs with QT, and one of them is it, i have two stopwatches, and one of them was working almost good (Very small percent of delay,almost 0), and the second one, was almost 35% of delay, horrible score.... The second one, is working on the same simple function, and i made it (It's a copy, with different variable name's).

      I was trying to find the issue, why one of the timer, working with a copy of function, was doing that.
      What's funny? When i just deleted the old TabWidget, and created new one (In general, i dont change any settings), now these two timers have the same delay of around 7-10%. I have no idea what's going on, and i have enough.

      If you can do something, cuz i have some bugs with my Qt, sometimes when i delete some objects, then when i press one button, the application crash, and i need to delete, and rebuild the project (It doesn't work if i just press the rebuild button, i lose a lot of time before i notice that).

      Release version is a completely mess up, simple calculations are giving some totally unknown results, basicly 100% is broken, functions are giving stuff from nowhere.

      If i switch to debug version, everything works good. Just the timers still have that low performance.

      I dont know if i should download newer version, and what is causing these problems.

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @Loc888 ,

      from what I read, you have a real mess at your hand ;-)

      Ok let us is break it down a bit

      I am having a lot of bugs with QT, and one of them is it, i have two stopwatches, and one of them was working almost good (Very small percent of delay,almost 0), and the second one, was almost 35% of delay, horrible score.... The second one, is working on the same simple function, and i made it (It's a copy, with different variable name's).

      Why don't you take your working StopWatch and move it into its own class? That why you can make 2 instances of the same base class/object that should behave always the same.

      Release version is a completely mess up, simple calculations are giving some totally unknown results, basicly 100% is broken, functions are giving stuff from nowhere.

      You need to initialize your variables the debug compiler initializes everything with 0, if you don't do it. The release one just takes what happens to be in the memory.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      L 1 Reply Last reply
      4
      • J.HilkJ J.Hilk

        hi @Loc888 ,

        from what I read, you have a real mess at your hand ;-)

        Ok let us is break it down a bit

        I am having a lot of bugs with QT, and one of them is it, i have two stopwatches, and one of them was working almost good (Very small percent of delay,almost 0), and the second one, was almost 35% of delay, horrible score.... The second one, is working on the same simple function, and i made it (It's a copy, with different variable name's).

        Why don't you take your working StopWatch and move it into its own class? That why you can make 2 instances of the same base class/object that should behave always the same.

        Release version is a completely mess up, simple calculations are giving some totally unknown results, basicly 100% is broken, functions are giving stuff from nowhere.

        You need to initialize your variables the debug compiler initializes everything with 0, if you don't do it. The release one just takes what happens to be in the memory.

        L Offline
        L Offline
        Loc888
        wrote on last edited by
        #3

        @J.Hilk I don't understand what you mean. The problem is with settext function now, when i use it, it's delays the time.

        1 Reply Last reply
        0
        • L Loc888

          Hi, i have some problems with QTimer, and label. I wanna create a simple stopwatch, but the time is highly delayed, it's around 15% different, so 30s is equal to 35s.

          Settext function is causing all the problems, and i need it to update the Ms label.

          I am having a lot of bugs with QT, and one of them is it, i have two stopwatches, and one of them was working almost good (Very small percent of delay,almost 0), and the second one, was almost 35% of delay, horrible score.... The second one, is working on the same simple function, and i made it (It's a copy, with different variable name's).

          I was trying to find the issue, why one of the timer, working with a copy of function, was doing that.
          What's funny? When i just deleted the old TabWidget, and created new one (In general, i dont change any settings), now these two timers have the same delay of around 7-10%. I have no idea what's going on, and i have enough.

          If you can do something, cuz i have some bugs with my Qt, sometimes when i delete some objects, then when i press one button, the application crash, and i need to delete, and rebuild the project (It doesn't work if i just press the rebuild button, i lose a lot of time before i notice that).

          Release version is a completely mess up, simple calculations are giving some totally unknown results, basicly 100% is broken, functions are giving stuff from nowhere.

          If i switch to debug version, everything works good. Just the timers still have that low performance.

          I dont know if i should download newer version, and what is causing these problems.

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @Loc888 said in Low performance, timer and label.:

          I am having a lot of bugs with Qt

          Don't blame the framework. We all did it at least once. It was never the framework's fault.

          Can you post your current code?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          L 1 Reply Last reply
          0
          • VRoninV VRonin

            @Loc888 said in Low performance, timer and label.:

            I am having a lot of bugs with Qt

            Don't blame the framework. We all did it at least once. It was never the framework's fault.

            Can you post your current code?

            L Offline
            L Offline
            Loc888
            wrote on last edited by
            #5

            @VRonin Give me back my wasted time, and i forgive him.

            VRoninV 1 Reply Last reply
            0
            • L Loc888

              @VRonin Give me back my wasted time, and i forgive him.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @Loc888 said in Low performance, timer and label.:

              Give me back my wasted time

              I could say the same here.

              If you want help, a bit of humility and accepting the fact that there's a 99.9% chance the problem is in your code and not in Qt is a first step

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              L 1 Reply Last reply
              3
              • VRoninV VRonin

                @Loc888 said in Low performance, timer and label.:

                Give me back my wasted time

                I could say the same here.

                If you want help, a bit of humility and accepting the fact that there's a 99.9% chance the problem is in your code and not in Qt is a first step

                L Offline
                L Offline
                Loc888
                wrote on last edited by Loc888
                #7

                @VRonin Ther is nothing to post, simple Qtimer and settext function. That's it.
                The timer refire the function, and set the current time.

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  Can you try this basic example?

                  #include <QApplication>
                  #include <QTimer>
                  #include <QLabel>
                  int main(int argc, char *argv[])
                  {
                      QApplication a(argc, argv);
                      QLabel mainWid;
                      QTimer mainTimer;
                      int counter = 0;
                      QObject::connect(&mainTimer,&QTimer::timeout,[&mainWid,&counter]()->void{
                          mainWid.setText(QObject::tr("%1 sec").arg(++counter));
                      });
                      mainTimer.start(1000);
                      mainWid.show();
                      return a.exec();
                  }
                  

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  L 1 Reply Last reply
                  3
                  • VRoninV VRonin

                    Can you try this basic example?

                    #include <QApplication>
                    #include <QTimer>
                    #include <QLabel>
                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                        QLabel mainWid;
                        QTimer mainTimer;
                        int counter = 0;
                        QObject::connect(&mainTimer,&QTimer::timeout,[&mainWid,&counter]()->void{
                            mainWid.setText(QObject::tr("%1 sec").arg(++counter));
                        });
                        mainTimer.start(1000);
                        mainWid.show();
                        return a.exec();
                    }
                    
                    L Offline
                    L Offline
                    Loc888
                    wrote on last edited by
                    #9

                    @VRonin It says no matching function.

                    VRoninV 1 Reply Last reply
                    0
                    • L Loc888

                      @VRonin It says no matching function.

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by VRonin
                      #10

                      @Loc888 I tested it on my machine Qt 5.10 MSVC2013 x64 Win7. What version of Qt are you running?

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      L 1 Reply Last reply
                      1
                      • VRoninV VRonin

                        @Loc888 I tested it on my machine Qt 5.10 MSVC2013 x64 Win7. What version of Qt are you running?

                        L Offline
                        L Offline
                        Loc888
                        wrote on last edited by
                        #11

                        @VRonin Desktop Qt 5.2.0 MinGW 32bit

                        1 Reply Last reply
                        0
                        • VRoninV Offline
                          VRoninV Offline
                          VRonin
                          wrote on last edited by VRonin
                          #12

                          Then everything should work, you probably just have to enable C++11

                          • add CONFIG += c++11 in your .pro file
                          • re-run qmake

                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                          ~Napoleon Bonaparte

                          On a crusade to banish setIndexWidget() from the holy land of Qt

                          L 1 Reply Last reply
                          1
                          • VRoninV VRonin

                            Then everything should work, you probably just have to enable C++11

                            • add CONFIG += c++11 in your .pro file
                            • re-run qmake
                            L Offline
                            L Offline
                            Loc888
                            wrote on last edited by
                            #13

                            @VRonin It's working, but i need it in MS. It happens because text need to be updated fast, and it cause the problem. If i just run the timer, it's look's fine, but i need to show the time in label..

                            J.HilkJ VRoninV 2 Replies Last reply
                            0
                            • L Loc888

                              @VRonin It's working, but i need it in MS. It happens because text need to be updated fast, and it cause the problem. If i just run the timer, it's look's fine, but i need to show the time in label..

                              J.HilkJ Online
                              J.HilkJ Online
                              J.Hilk
                              Moderators
                              wrote on last edited by J.Hilk
                              #14

                              @Loc888 I think you need to be a bit more specific, with what is going on.

                              It's working, but i need it in MS. It happens because text need to be updated fast, and it cause the problem. If i just run the timer, it's look's fine, but i need to show the time in label..

                              Updating a QLabel's text shouldn't take seconds to update

                              to modify the code of @VRonin abit to display time and fast changes:

                              #include <QApplication>
                              #include <QTimer>
                              #include <QLabel>
                              #include <QTime>
                              
                              int main(int argc, char *argv[])
                              {
                                  QApplication a(argc, argv);
                              
                                  QLabel mainWid;
                                  QTimer mainTimer;
                                  QObject::connect(&mainTimer,&QTimer::timeout,[&mainWid]()->void{
                                     mainWid.setText(QTime::currentTime().toString("hh.mm.ss.zz"));
                                  });
                                  mainTimer.start(10);
                                  mainWid.show();
                              
                                  return a.exec();
                              }
                              

                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              L 1 Reply Last reply
                              2
                              • J.HilkJ J.Hilk

                                @Loc888 I think you need to be a bit more specific, with what is going on.

                                It's working, but i need it in MS. It happens because text need to be updated fast, and it cause the problem. If i just run the timer, it's look's fine, but i need to show the time in label..

                                Updating a QLabel's text shouldn't take seconds to update

                                to modify the code of @VRonin abit to display time and fast changes:

                                #include <QApplication>
                                #include <QTimer>
                                #include <QLabel>
                                #include <QTime>
                                
                                int main(int argc, char *argv[])
                                {
                                    QApplication a(argc, argv);
                                
                                    QLabel mainWid;
                                    QTimer mainTimer;
                                    QObject::connect(&mainTimer,&QTimer::timeout,[&mainWid]()->void{
                                       mainWid.setText(QTime::currentTime().toString("hh.mm.ss.zz"));
                                    });
                                    mainTimer.start(10);
                                    mainWid.show();
                                
                                    return a.exec();
                                }
                                
                                L Offline
                                L Offline
                                Loc888
                                wrote on last edited by
                                #15

                                @J.Hilk I would like to use that, but i don't want current time, i want everything starting from 0.

                                J.HilkJ 1 Reply Last reply
                                0
                                • L Loc888

                                  @J.Hilk I would like to use that, but i don't want current time, i want everything starting from 0.

                                  J.HilkJ Online
                                  J.HilkJ Online
                                  J.Hilk
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  @Loc888
                                  this code examples are for the purpose of trouble shooting.
                                  But it's easy enought to adapt.

                                  #include <QApplication>
                                  #include <QTimer>
                                  #include <QLabel>
                                  #include <QTime>
                                  #include <QElapsedTimer>
                                  int main(int argc, char *argv[])
                                  {
                                      QApplication a(argc, argv);
                                  
                                      QLabel mainWid;
                                      QTimer mainTimer;
                                      QTime time(0,0);
                                      QElapsedTimer actualTimePassed;
                                      QObject::connect(&mainTimer,&QTimer::timeout,[&mainWid, &time, &actualTimePassed]()->void{
                                          time = time.addMSecs(actualTimePassed.elapsed());
                                          actualTimePassed.start();
                                          mainWid.setText(time.toString("hh.mm.ss.zzz"));
                                      });
                                      actualTimePassed.start();
                                      mainTimer.start(10);
                                      mainWid.show();
                                  
                                      return a.exec();
                                  }
                                  

                                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                  Q: What's that?
                                  A: It's blue light.
                                  Q: What does it do?
                                  A: It turns blue.

                                  L 1 Reply Last reply
                                  0
                                  • L Loc888

                                    @VRonin It's working, but i need it in MS. It happens because text need to be updated fast, and it cause the problem. If i just run the timer, it's look's fine, but i need to show the time in label..

                                    VRoninV Offline
                                    VRoninV Offline
                                    VRonin
                                    wrote on last edited by VRonin
                                    #17

                                    @Loc888 said in Low performance, timer and label.:

                                    it's working, but i need it in MS

                                    Unfortunately this is platform dependant. Best you could do is:

                                    #include <QApplication>
                                    #include <QTimer>
                                    #include <QLabel>
                                    
                                    int main(int argc, char *argv[])
                                    {
                                        QApplication a(argc, argv);
                                        QLabel mainWid;
                                        QTimer mainTimer;
                                        mainTimer.setTimerType(Qt::PreciseTimer);
                                        unsigned int counter = 0;
                                        QObject::connect(&mainTimer,&QTimer::timeout,[&mainWid,&counter]()->void{
                                            mainWid.setText(QObject::tr("%1 msec").arg(++counter));
                                            mainWid.repaint();
                                        });
                                        mainTimer.start(1);
                                        mainWid.show();
                                        return a.exec();
                                    }
                                    

                                    Please note, from http://doc.qt.io/qt-5/qt.html#TimerType-enum:

                                    Precise timers try to keep millisecond accuracy

                                    try != will, unfortunately

                                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                    ~Napoleon Bonaparte

                                    On a crusade to banish setIndexWidget() from the holy land of Qt

                                    L 1 Reply Last reply
                                    1
                                    • VRoninV VRonin

                                      @Loc888 said in Low performance, timer and label.:

                                      it's working, but i need it in MS

                                      Unfortunately this is platform dependant. Best you could do is:

                                      #include <QApplication>
                                      #include <QTimer>
                                      #include <QLabel>
                                      
                                      int main(int argc, char *argv[])
                                      {
                                          QApplication a(argc, argv);
                                          QLabel mainWid;
                                          QTimer mainTimer;
                                          mainTimer.setTimerType(Qt::PreciseTimer);
                                          unsigned int counter = 0;
                                          QObject::connect(&mainTimer,&QTimer::timeout,[&mainWid,&counter]()->void{
                                              mainWid.setText(QObject::tr("%1 msec").arg(++counter));
                                              mainWid.repaint();
                                          });
                                          mainTimer.start(1);
                                          mainWid.show();
                                          return a.exec();
                                      }
                                      

                                      Please note, from http://doc.qt.io/qt-5/qt.html#TimerType-enum:

                                      Precise timers try to keep millisecond accuracy

                                      try != will, unfortunately

                                      L Offline
                                      L Offline
                                      Loc888
                                      wrote on last edited by
                                      #18

                                      @VRonin Maybe i expressed wrong, but i don't want it in Ms (the total), so 5500 = 5,5s, i want that pattern "mm.ss.zzz" or "mm.ss.zz" , but i want it to start from 0, not from the current time. Is any way to force it? (In sec, ther is no delay when the method update the text).

                                      1 Reply Last reply
                                      0
                                      • J.HilkJ J.Hilk

                                        @Loc888
                                        this code examples are for the purpose of trouble shooting.
                                        But it's easy enought to adapt.

                                        #include <QApplication>
                                        #include <QTimer>
                                        #include <QLabel>
                                        #include <QTime>
                                        #include <QElapsedTimer>
                                        int main(int argc, char *argv[])
                                        {
                                            QApplication a(argc, argv);
                                        
                                            QLabel mainWid;
                                            QTimer mainTimer;
                                            QTime time(0,0);
                                            QElapsedTimer actualTimePassed;
                                            QObject::connect(&mainTimer,&QTimer::timeout,[&mainWid, &time, &actualTimePassed]()->void{
                                                time = time.addMSecs(actualTimePassed.elapsed());
                                                actualTimePassed.start();
                                                mainWid.setText(time.toString("hh.mm.ss.zzz"));
                                            });
                                            actualTimePassed.start();
                                            mainTimer.start(10);
                                            mainWid.show();
                                        
                                            return a.exec();
                                        }
                                        
                                        L Offline
                                        L Offline
                                        Loc888
                                        wrote on last edited by Loc888
                                        #19

                                        @J.Hilk Guys,i tried J.Hilk code,and it's not working how it should.

                                        It doesnt help me, it's working, but if i compare the timer to my windows time, the difference is arround 10s (after 2min test), it's too mutch.

                                        Why it's happening?

                                        Ps. I tried with "setTimerType(Qt::PreciseTimer);", but still doesn't help...

                                        ????????

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          mpergand
                                          wrote on last edited by
                                          #20

                                          My turn ;)

                                          QLabel label;
                                          label.setGeometry(100,100,200,50);
                                           QTimer timer;
                                           QTime time;
                                          
                                           QObject::connect(&timer,&QTimer::timeout,[&time,&label](){
                                              QTime elapsed=QTime::fromMSecsSinceStartOfDay(time.elapsed());
                                              label.setText(elapsed.toString("mm:ss:zzz"));
                                              });
                                          
                                          time.start();
                                          timer.start(100);
                                          label.show();
                                          
                                          L 1 Reply Last reply
                                          5

                                          • Login

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