[Interest] QTimer and QThread

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Wed Jul 31 13:20:51 CEST 2013


On Wed, Jul 31, 2013 at 2:31 PM, Alexander Syvak <alexander.svk at gmail.com>wrote:

> Here's the snippet below from implementation of the run method. The class
> inherits a class inheriting QThread.
> ...
>        screenshot_qtmr = new QTimer;//(this);
>
>     screenshot_qtmr->moveToThread(this);
>
>
This stmt is not necessary as the QTimer instance is created in the new
thread itself.

    qDebug() << connect(screenshot_qtmr, SIGNAL(timeout()), this,
SLOT(on_screenshot_timeout()));
>
>     qDebug() << connect(this, SIGNAL(kill_tmr()), screenshot_qtmr, SLOT(stop()));
>
>
 The  on_screenshot_timeout() will get called in the context of "main"
thread, not this new thread. Hope thats what you intended.

     screenshot_qtmr->start(freq*1000);
>
>     anal_qmr = new QTimer;//(this);
>
>     anal_qmr->moveToThread(this);
>
>     qDebug() << connect(anal_qmr, SIGNAL(timeout()), SLOT(on_analize_timeout()));
>
>     qDebug() << connect(this, SIGNAL(kill_tmr()), anal_qmr, SLOT(stop()));
>
>     anal_qmr->start(state_analizer_tmr_interval);
>
>     if ( !state_analizer_tmr_id ) return;
>
>

>
>     exec();    while ( !stop );
>
>
Whats the point of this while loop here? You'll return from exit if someone
calls exit() on it. Wouldn't you want to quit after that?

Your slot should get called, unless the timer has been stopped due to some
reason. Are you certain the timer is running (eg it's not been stopped by
the "kill_tmr()" signal)?

HTH,
-mandeep



>
>
> }
>
> Here's an ouput
> run() "./13_7_31_10_49_2_974"
>
> "./13_7_31_10_49_2_974 exists"
>
> "./13_7_31_10_49_2_974 has 'write' permission for other"
>
> "./13_7_31_10_49_2_974/S0 directory was created"
>
> true
>
> true
>
> true
>
> true
>
> run() "./13_7_31_10_49_2_974"
>
> "./13_7_31_10_49_2_974 exists"
>
> "./13_7_31_10_49_2_974 has 'write' permission for other"
>
> "./13_7_31_10_49_2_974/S1 directory was created"
>
> true
>
> true
>
> true
>
> true
>
>
> It never enters those method specified on timeout(). Why?
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130731/ae6b8312/attachment.html>


More information about the Interest mailing list