Yes, this is a FAQ, but I can’t seem to figure out what I am doing wrong. I am
using the worker pattern of QThread, (as opposed to subclassing), running Qt
5.15.2. In my controller’s constructor, I have the following code to initialize
a worker:
worker=new VLCWorker();
worker->moveToThread(&vlcWorkerThread);
worker->initVLC(videoWin);
vlcWorkerThread.start();
The initVLC function, among other things, creates a timer and connects it to a
slot in the worker:
rtspStartTimer=new QTimer;
rtspStartTimer->setSingleShot(true);
connect(rtspStartTimer, &QTimer::timeout,
this, &VLCWorker::rtspStarting);
Later, at some point during program execution, I try to start this timer from a
function in the worker (which itself was triggered by a signal from the main
thread):
qDebug()<<"*****Trying to start timer which lives in
thread"<<(long)rtspStartTimer->thread()<<" from thread "<<(long)this->thread();
rtspStartTimer->start(250);
qDebug()<<"*****Timer attempt complete";
Unfortunately, this doesn’t work, giving me the following output:
Debug: 2021-07-18T19:26:12.009 - *****Trying to start timer which lives in
thread 140235980165688 from thread 140235980165688
(../DoorBellCamC/vlccontroller.cpp:121, void VLCWorker::rtspStarting())
Warning: 2021-07-18T19:26:12.009 - QObject::startTimer: Timers cannot be
started from another thread (:0, )
Debug: 2021-07-18T19:26:12.009 - *****Timer attempt complete
(../DoorBellCamC/vlccontroller.cpp:123, void VLCWorker::rtspStarting())
So even though the output of the debug confirms that the timer lives in the
same thread I am trying to call start from, I still get the error about “timers
cannot be started from another thread”. What am I doing wrong?
---
Israel Brewster
Software Engineer
Alaska Volcano Observatory
Geophysical Institute - UAF
2156 Koyukuk Drive
Fairbanks AK 99775-7320
Work: 907-474-5172
cell: 907-328-9145
_______________________________________________
Interest mailing list
[email protected]
https://lists.qt-project.org/listinfo/interest