PDA

View Full Version : how to enable a timer in a non-gui thread?



zeopha
3rd August 2008, 19:31
I have a non-gui thread to process db files , and I want a slot located in this thread to check the db files every a threshold assigned by a QTimer. the slot will emit a signal to post information to a gui thread to show db files' status. but the slot connected to this timer won't work in this thread.
I don't want to use such soluton:
this timer was located in the gui thread and was connected a slot located in that non-gui thread.

how can I enable this timer in such non-gui thread in some other solution?

any help will be appreciated!

lvi
4th August 2008, 08:28
I'm not sure what your problem is?
Is it that a QTimer in the GUI thread is not triggering the slot in the DB thread?
Can you maybe post some code that clarifies what is not working and/or the solution you don't want to use?

Khal Drogo
4th August 2008, 13:23
Zeopha, your problem more than likely is that you forgot to call exec() in your thread's run function. Without calling exec, the thread won't have an event loop, which is necessary for the use of QTimer.
Read the documentation for QTimer and QThread for more info.

I hope that answers your question.

zeopha
5th August 2008, 09:29
to Lvi:
a timer located in the main gui widget will trigger the slot in another qthread. but I just think that the timer should not be located in the gui :)

to:Khal Drogo

U r right. I had forgetten to execute the exec() in the run function of thread. So am I stupid!!!

thanks to Liv and Khal Drogo !