Qt and POSIX
-
I have to develop a Linux daemon that uses the POSIX API to create POSIX threads and POSIX message queues. I would like to use Qt to develop this daemon to take advantage of the Qt libraries and signal/slot mechanism, understanding that the application will not be platform independent. Is it possible to use POSIX API for POSIX threads and message queues with Qt and signals/slots? If so, is there an example of how to do this?
-
These are three questions:
1.) can you use POSIX functions inside Qt? Anser is yes, its C/C++ and you can do anything that C/C++ allows.
2.) Can you use possix threads? Theoretically yes. But, and that is the important thing, you can't use signal/slot across threads without using QtThreads and Qt message loops.
3.) What do you want to do with POSIX message queues? Inter process communication? Then see answer 1 :-)
-
[quote]2.) Can you use possix threads? Theoretically yes. But, and that is the important thing, you can’t use signal/slot across threads without using QtThreads and Qt message loops.[/quote]
This is slightly incorrect -- you can mix QThread and native threads, and even use signals from native threads.
-
You can emit Signals from natic threads, but can't use slots inside them :-)
But I think,. on Linux, QThread objects just encapsulate POSIX threads, don't they?But for cross thread signal/slot you need QThreads (at least for the receiving thread) and there a QMessageLoop.
-
Take a look at the "QtService solution":https://qt.gitorious.org/qt-solutions. I have used this successfully in the past.
I would just use QThread for conveniemce since it just wraps POSIX threads.
-
Just a note: Local sockets would be more portable than POSIX message queues. Also it scales better if you intend to distribute among more machines later. (see: http://doc.qt.nokia.com/4.7-snapshot/qlocalsocket.html
[EDIT: fixed link, Volker]
-
I am using native threads emitting signals to Qt main thread and seems to work, but I'm searching for a technique similar to QMetaObject's invokeMethod()
Is that possible?