[Qt-interest] Basic QThread question
Sean Harmer
sean.harmer at maps-technology.com
Fri May 7 10:14:02 CEST 2010
Hi Phil,
On 07/05/2010 08:38, Sean Harmer wrote:
> 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.
Please try the attached application. Instead of querying your device it
simply generates a random number. If you set breakpoints in the
DataProcessor::processData(int x) and DevicePoller::poll() methods then
look at the Threads debug view in creator you will see that this does
work using two threads and that the "polling" is performed in the worker
thread as expected. The main thread function simpy prints out the square
of the random number generated by the worker thread.
Hopefully this will allow you to get it working with your polling code.
Just replace the call to qrand() % 10 with your own code.
HTH,
Sean
-------------- next part --------------
A non-text attachment was scrubbed...
Name: threadedpoller.zip
Type: application/x-zip-compressed
Size: 4483 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100507/99aabe0e/attachment.bin
More information about the Qt-interest-old
mailing list