[Qt-interest] Slots in threads ?
Patric
userqt at gmail.com
Thu Aug 27 19:43:50 CEST 2009
Hi Will,
this approach to use directly the QThread is interesting. I have used the method with moveToThread() with derived one.
Anyway, I think in my case I can do it the way it's done in the Mandelbrot example. There is a forever loop in run(), at the end of which condition.wait() is called. And when we want to wake it, we just call some method in our derived thread which wakes it. :)
In my case I need the process to be interrupted at any time, so I think this will be the better way.
Regards
----- Original Message -----
From: Will Rutherdale (rutherw)
To: qt-interest at trolltech.com
Sent: Thursday, August 27, 2009 8:07 PM
Subject: Re: [Qt-interest] Slots in threads ?
The way I normally do it is to have a worker object (with class derived from QObject) and call the object's moveToThread() to attach it to your thread. You do not subclass QThread but use it directly, then call its start(). This will run its event loop by default. You connect slots in the worker object to the appropriate signals. Then when those signals are emitted the object will do its work within the thread.
-Will
----------------------------------------------------------------------------
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Patric
Sent: 27 August 2009 12:48
To: qt-interest at trolltech.com
Subject: [Qt-interest] Slots in threads ?
Hello,
I have a little gui program with one worker thread. I want to stop and start the thread from the gui. So I put some slots inside the thread. But now I'm getting some errors on compilation :
mainwindow.cpp: In constructor `MainWindow::MainWindow(QWidget*)':
mainwindow.cpp:35: error: no matching function for call to `MainWindow::connect(Board*&, const char*, Engine*, const char*)'
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/kernel/qobject.h:202: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/kernel/qobject.h:308: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
Am I allowed to put slots in threads ?
Regards
------------------------------------------------------------------------------
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090827/e15fad47/attachment.html
More information about the Qt-interest-old
mailing list