설명서를 살펴본 결과 고유 ID를 재사용하는 것에 대해 찾지 못했습니다.QTimer가 고유 ID를 사용하지 않습니까?
The function returns a unique integer timer ID
그러나 것은 얼마나 독특한 것 :
문서는가 startTimer 기능에 대해 말한다? 그것은 어떤 시점에서 ID를 재사용합니까?
설명서를 살펴본 결과 고유 ID를 재사용하는 것에 대해 찾지 못했습니다.QTimer가 고유 ID를 사용하지 않습니까?
The function returns a unique integer timer ID
그러나 것은 얼마나 독특한 것 :
문서는가 startTimer 기능에 대해 말한다? 그것은 어떤 시점에서 ID를 재사용합니까?
하지만 얼마나 오래 될 것입니까?
타이머 ID는 QAbstractEventDispatcherPrivate :: releaseTimerId()를 통해 출시 될 때까지 고유해야합니다.
즉, killTimer()를 호출합니다.
나는 빨리보기 위해 간단한 테스트를 썼다 :어떤 시점에서 ID를 다시 사용합니까?
Something.h :
#include <QCoreApplication> #include <QtCore> #include <QtGlobal> class Something : public QObject { Q_OBJECT public: Something() : QObject() {} ~Something() {} };
MAIN.CPP :
#include "Something.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Something thing; int i = thing.startTimer(1000); qDebug() << i; thing.killTimer(i); i = thing.startTimer(1000); qDebug() << i; return a.exec(); }
결과를 타이머 ID를 다시 얻을 것이다 경우
1
1
class Something : public QObject
{
Q_OBJECT
public:
Something() : QObject(), timer(NULL) {}
~Something() {}
void runme()
{
timer = new QTimer();
// Old school ;)
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timerEvent()));
timer->start(100);
}
public Q_SLOTS:
void timerEvent()
{
qDebug() << timer->timerId();
timer->stop();
delete timer;
timer = new QTimer();
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timerEvent()));
timer->start(1000);
}
public:
QTimer* timer;
};
그럼 그냥 킥오프하고 실행 :3210
마지막으로, 독점적으로 QTimer를 사용하여 ... 당신과 함께 테스트 할 수 있습니다
Something thing;
thing.runme();
내가 내려 qabstracteventdispatcher 모든 방법을 추적 할 수 있었다. src/qtbase/src/corelib/kernel에서 Qt 5.2에 대한 cpp/.h를 입력하십시오. 해당 파일의 맨 위가 매개 변수를 설정하고 QAbstractEventDispatcherPrivate :: allocateTimerId()를 들여다 볼 수 있습니다. – Huy
[documentation] (http://qt-project.org/doc/qt-4.8/qtimer.html#alternatives-to-qtimer)에 따르면 타이머의 수와 동일한 수의 타이머를 생성 할 수있는 능력이 있습니다. 운영 체제가 제공 할 수 있습니다. –