[SOLVED]Communication between QRunnable and main thread
-
Hi,
I was looking into the ThreadPool threading option in Qt and just realized that QRunnable doesn't inherit QObject so you can't send signals with it .The only working option I have from "here":http://www.qtcentre.org/threads/37340-Communication-between-QRunnable-and-main-thread is embedding a QObject member and sending the signal with it .Is there any other way you have guys of communicating with the GUI thread?
Thanks.
-
Thanks for the quick reply,
I was trying using :
@class MyRunnable : public QRunnable, public QObject { ... };
@
And it gave those metaobject errors and unresolved symbols.But inheriting QObject first is working .Any Idea why we have to inherit QObject first here?
Also I how does one go about the postEvent solution suggested at that link.
Thanks.
-
[quote author="musimbate" date="1396759690"]Any Idea why we have to inherit QObject first here?
[/quote]One of the "moc limitations":http://qt-project.org/doc/qt-5/moc.html#multiple-inheritance-requires-qobject-to-be-first
-
[quote author="musimbate" date="1396759690"]
Also I how does one go about the postEvent solution suggested at that link.
[/quote]You can create your own QEvent (or inherited from QEvent) event-object and send it to QObject based object using
@
QCoreApplication::postEvent()
@You can postEvent from any object not only QObject based. The receiver of the object must be QObject based.
More "info":http://qt-project.org/doc/qt-5/eventsandfilters.html#sending-events
And here is a simple "example":http://qt-project.org/doc/qt-5/qtwidgets-statemachine-pingpong-example.html -
If you're ready to use Qt only as an OS interface (GUI, sockets, whatever), and clearly separate your app from the Qt interface, i'll publish a multi-threading framework in a week or two. The code works, but i still have to finish the documentation, and i expect this to take me a couple of weeks or so. If you wanna check out what the lib does, the current state of the doc is here: http://www.itgroup.ro/libposif-app-brief.pdf
-
@musimbate: ok, stay subscribed to this forum thread and i'll drop a line here with the details when i'll publish it (it'll prolly be on sourceforge, but ain't sure yet).
Cheers!
-
well, it took a while, but here it is: http://libagents.sourceforge.net/