int main(int argc, char *argv[])
{
// QCoreApplication a(argc, argv);
My_WindowsService service(argc, argv);
My_CustomFunction NewCustomFunction;
QTimer * pQTimer = new QTimer(&NewCustomFunction);
QObject::connect(pQTimer,SIGNAL(timeout()),&NewCustomFunction,SLOT(TestPrint()));
pQTimer->start(3000);
return service.exec();
// return a.exec();
}
會提示[Warning]QObject::startTimer: Timers can only be used with threads started with QThread
把定時器代碼放在My_WindowsService的建構式或者重寫的start()函式里面也是不行的。
uj5u.com熱心網友回復:
QTimer * pQTimer = new QTimer(&NewCustomFunction); 這里別指定parent,改成QTimer * pQTimer = new QTimer(nullptr);然后,把該timer QThread::moveToThread(你用該timer的執行緒);
uj5u.com熱心網友回復:
這種需要通過connect系結物件吧,但是我需要的函式都不在類里面. 難道都要封裝嗎...
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/84472.html
標籤:Qt
