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...
Forum Updated to NodeBB v4.3 + New Features

My QTimer isnt working...

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtimerc++
4 Posts 3 Posters 579 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 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.HilkJ 1 Reply Last reply
    0
    • R RuWex

      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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on 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
      2
      • J.HilkJ J.Hilk

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

        whats wrong

        object lifetime, stack vs heap

        R Offline
        R Offline
        RuWex
        wrote on last edited by
        #3

        @J-Hilk
        ??
        what do you mean?

        jsulmJ 1 Reply Last reply
        0
        • R RuWex

          @J-Hilk
          ??
          what do you mean?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #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

          • Login

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