[Qt-interest] Basic QThread question

Sean Harmer sean.harmer at maps-technology.com
Fri May 7 09:38:47 CEST 2010


Hi Phil,

On 07/05/2010 02:31, Phil wrote:
> On Thu, 6 May 2010 07:40:49 pm Sean Harmer wrote:
>> Hi,
>>>
>>> Yes, but the OP does seem to get the code working but still running in
>>> the GUI thread. Based on my experience on a similar problem and
>>> referring to the previous list entry (see link in my first reply) this
>>> was the solution. Maybe this is not the case here, but it might be...
>>
>> I know what you mean, but let's wait and see if the OP posts some more
> of
>>   his main thread code as requested. :-)
>
> Thank you for the replies, more food for thought.
>
> I fear that I may not have stated the problem clearly enough. As I see it, the
> problem is in the original code that Sean kindly sent me. I wanted to know if
> there is a typo in this line:
>
>> connect( m_workerThread->poller(), SIGNAL( value( int ) ),
>>           this, SLOT( processValue( int ) ) );
>
> There isn't a poller() function and if I create one then this is the result:

Yes there was:

DevicePoller* poller() const { return m_poller; }

It simply returns a pointer to the DevicePoller object that is a child 
of the worker thread object.

> "invalid use of void expression"

Ah, maybe it is an ordering problem as the DevicePoller object is not 
created until the run() function is called from the worker thread's 
context. Before this, the pointer value will be 0.

Bear with me for a few minutes and I will make a small application that 
works but will just generate random numbers in a worker thread using the 
above method. I'll post it to the list shortly for you, then all you 
have to do is to insert the code that talks to your device.

All that is missing is waiting for the DevicePoller object to be created 
before connecting to it.

> I've been working on this application for a little over ten years, on and off,
> and it has grown somewhat during that time. I have added the most time-
> intensive code into the function DevicePoller::poll() which still works but it
> blocks the GUI. Writing to and reading from the hardware is not the problem,
> as far as I can tell, because it all works correctly.
>
> I'm happy to supply more code but I think the problem is in the connect line
> above.

OK hold fire on that and give me 10 minutes. Get back to you soon...

Sean



More information about the Qt-interest-old mailing list