My QTimer isnt working...
Unsolved
General and Desktop
-
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? -
-
@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); });