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. My QTimer isnt working...
QtWS25 Last Chance

My QTimer isnt working...

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtimerc++
4 Posts 3 Posters 556 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.
  • R Offline
    R Offline
    RuWex
    wrote on 8 Nov 2022, 09:09 last edited by
    #1

    MainWindow.cpp:

     button->show();
                 connect(button, &QPushButton::clicked, this, [=]() {
    statusBar()->showMessage(tr("Ready Start Testing"), 2000);
                     Timer timer(num, fileName);
                                  });
    

    timer.cpp:

    #include <QDebug>
    #include <QTimer>
    #include "timer.h"
    
    
    Timer::Timer(int num, QString fileName)
    {
           m_timer= new QTimer(this);
           m_send= new SendCommands();
           m_timeTimer= num;
           m_fileName= fileName;
    
           connect(m_timer, SIGNAL(timeout()), this, SLOT(MySlots()));
           m_timer->start(m_timeTimer);
           if (firstTime)
           {
               MySlots();
           }
           firstTime=false;
    }
    
    
    void Timer:: MySlots()
    {
        qDebug()<<"print..."<<endl;
        m_send->StartToSendCommand(m_fileName);
    }
    
    

    sendCommands.cpp:

    void SendCommands::StartToSendCommand( QString fileName)//Ruth
    {
     
        Timer time(2000, fileName);
        MainSendCommand mainSendCom;
        mainSendCom.mainwind->ChangeStatus("send commands");
        bool ans=additionalTest->CountsTheTimeRemaining(fileName);
        if (ans)
        {
            QFile file(fileName);
            if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                return;
    
            QTextStream in(&file);
            QString line;
            while (!in.atEnd()) {
    
                line = in.readLine();
    
                QApplication::processEvents();
    
            }
    
        }
        else {
            return;
        }
    
    }
    

    but, the timer doesnt working:(
    what I actually want is that when the betton would press the function every X minute will worked.
    whats wrong?

    J 1 Reply Last reply 8 Nov 2022, 09:21
    0
    • R RuWex
      8 Nov 2022, 09:09

      MainWindow.cpp:

       button->show();
                   connect(button, &QPushButton::clicked, this, [=]() {
      statusBar()->showMessage(tr("Ready Start Testing"), 2000);
                       Timer timer(num, fileName);
                                    });
      

      timer.cpp:

      #include <QDebug>
      #include <QTimer>
      #include "timer.h"
      
      
      Timer::Timer(int num, QString fileName)
      {
             m_timer= new QTimer(this);
             m_send= new SendCommands();
             m_timeTimer= num;
             m_fileName= fileName;
      
             connect(m_timer, SIGNAL(timeout()), this, SLOT(MySlots()));
             m_timer->start(m_timeTimer);
             if (firstTime)
             {
                 MySlots();
             }
             firstTime=false;
      }
      
      
      void Timer:: MySlots()
      {
          qDebug()<<"print..."<<endl;
          m_send->StartToSendCommand(m_fileName);
      }
      
      

      sendCommands.cpp:

      void SendCommands::StartToSendCommand( QString fileName)//Ruth
      {
       
          Timer time(2000, fileName);
          MainSendCommand mainSendCom;
          mainSendCom.mainwind->ChangeStatus("send commands");
          bool ans=additionalTest->CountsTheTimeRemaining(fileName);
          if (ans)
          {
              QFile file(fileName);
              if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                  return;
      
              QTextStream in(&file);
              QString line;
              while (!in.atEnd()) {
      
                  line = in.readLine();
      
                  QApplication::processEvents();
      
              }
      
          }
          else {
              return;
          }
      
      }
      

      but, the timer doesnt working:(
      what I actually want is that when the betton would press the function every X minute will worked.
      whats wrong?

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 8 Nov 2022, 09:21 last edited by
      #2

      @RuWex said in My QTimer isnt working...:

      whats wrong

      object lifetime, stack vs heap


      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.

      R 1 Reply Last reply 8 Nov 2022, 09:23
      2
      • J J.Hilk
        8 Nov 2022, 09:21

        @RuWex said in My QTimer isnt working...:

        whats wrong

        object lifetime, stack vs heap

        R Offline
        R Offline
        RuWex
        wrote on 8 Nov 2022, 09:23 last edited by
        #3

        @J-Hilk
        ??
        what do you mean?

        J 1 Reply Last reply 8 Nov 2022, 09:25
        0
        • R RuWex
          8 Nov 2022, 09:23

          @J-Hilk
          ??
          what do you mean?

          J Online
          J Online
          jsulm
          Lifetime Qt Champion
          wrote on 8 Nov 2022, 09:25 last edited by jsulm 11 Aug 2022, 09:27
          #4

          @RuWex What do you think how long does "time" object exist here:

          void SendCommands::StartToSendCommand( QString fileName)//Ruth
          {
           
              Timer time(2000, fileName);
          

          ?

          Or "timer" here:

          button->show();
                       connect(button, &QPushButton::clicked, this, [=]() {
                           statusBar()->showMessage(tr("Ready Start Testing"), 2000);
                           Timer timer(num, fileName);
                       });
          

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

          1 Reply Last reply
          2

          3/4

          8 Nov 2022, 09:23

          • Login

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