我在Qt C++中遇到了QTimer的問題,在我的代碼中沒有調用timeoutHandler()。任何人都可以告訴我爲什麼以及如何修復它?Qt C++ QTimer不會調用處理程序
Test.h
class Test : public QObject
{
Q_OBJECT
private:
static bool timeOuted;
public:
explicit Test(QObject *parent = 0);
virtual ~Test();
public slots:
static void handleTimeout();
};
Test.cpp的
void Test::run()
{
QTimer::singleShot(3000, this, SLOT(handleTimeout()));
while(!timeOuted);
if(timeOuted)
{
timeOuted = false;
}
else
{
/* some work */
}
}
bool Test::timeOuted = false;
void Test::handleTimeout()
{
static int i = 0;
timeOuted = true;
qDebug() << "TimeOuted " << i++;
}
試着讓你的handleTimeout非靜態? – 2014-10-01 13:02:53