[Interest] Difficulty running Timer from QThread

Israel Brewster ijbrewster at alaska.edu
Tue Jul 20 21:10:17 CEST 2021


For what it’s worth, it doesn’t appear that the thread in which the QTimer object lived was ever the problem. Even when I first asked the question, calling rtspStartTimer->thread() returned the correct thread (or at least the same thread as calling this->thread() from a parent class function).

While I have since implemented the suggestions of running the init function in response to the QThread started() signal, as well as adding a parent for the QTimer, the actual fix was when I discovered that the function that called start was *not* running in the thread I thought it was (i.e. some thread other than vlcWorkerThread).

From what I can tell, that function being called from the unknown thread was the complete cause of the issue.

Thanks all for the help!
---
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

> On Jul 20, 2021, at 10:40 AM, Björn Schäpers <qt-maillist at hazardy.de> wrote:
> 
> Am 20.07.2021 um 06:19 schrieb Thiago Macieira:
>> On Monday, 19 July 2021 11:51:30 PDT Björn Schäpers wrote:
>>> Yes, and the Timer was created inside the VLCWorker::initVLC, and said
>>> worker was moved, but before initVLC, but initVLC was called in the moved
>>> from thread.
>> But the QTimer had no parent. From the OP:
>> 
>> rtspStartTimer=new QTimer;
>> rtspStartTimer->setSingleShot(true);
>> connect(rtspStartTimer, &QTimer::timeout,
>>         this, &VLCWorker::rtspStarting);
>> 
>> That means this QTimer wasn't moved and therefore was firing on the thread
>> that created the object. Whichever that was.
>> 
> Last response. Yes that's why I advised to parent it, and THEN move to the other thread. The Timer would have been moved with its parent.
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210720/15e04670/attachment.html>


More information about the Interest mailing list