我想在我的常规类(class)中使用 QTimer(没有 QT 应用程序,但派生自 QTimer)。但是当我尝试这个时:
标题:
#include <qtimer.h>
QTimer* m_timer;
public slots:
void UpdateClock();
来源:
m_timer = new QTimer(this);
QObject::connect(m_timer, SIGNAL(timeout()), this, SLOT(UpdateClock()));
m_timer->start(1000);
void MyClass::UpdateClock()
{
int i = 0;
}
计时器永远不会跳转到 UpdateClock 方法!你知道我为什么以及如何解决这个问题吗??
谢谢!
最佳答案
QTimer 依赖于 QCoreApplication。如果您不启动 QCoreApplication,则不会激活 QTimer。 (QApplication继承QCoreApplication,通常使用。)
关于c++ - 如何在没有 QT 应用程序的情况下使用 QTimer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20562142/