[Qt-interest] Basic QThread question

Sean Harmer sean.harmer at maps-technology.com
Thu May 6 11:21:27 CEST 2010


Hi,

On Thursday 06 May 2010 10:12:15 Eirik Ulvik wrote:
> I had trouble using timers in threads before and used this info:
> http://lists.trolltech.com/qt-interest/2007-09/thread00073-0.html.
> 
> Basically this would translate to:
> >> class DevicePoller : public QObject
> >> {
> >> Q_OBJECT
> >> 
> >> public:
> >>     DevicePoller( QObject* parent = 0 )
> >>     
> >>     : QObject( parent ), m_timer( new QTimer( this ) )
> >>     
> >>     {
> 
>           connect(this, SIGNAL(started()), this, SLOT(handleStarted()));
> 
> >>         connect( m_timer, SIGNAL( timeout() ), SLOT( poll() ) );
> >>         m_timer->start( 1000 );
> >>     
> >>     }
> >> 
> >> public slots:
> >>     void poll()
> >>     {
> >>     
> >>         // Talk to your device here
> >>         ...
> >>         int x = ...
> >>         
> >>         // Let the world know the value retrieved
> >>         emit value( x );
> >>     
> >>     }
> 
> private slots:
>      void handleStarted()
>      {
>         moveToThread(this);
>      }

I do not think this is correct. DevicePoller is not a QThread it is a QObject 
so it has no started() signal.

Cheers,

Sean




More information about the Qt-interest-old mailing list