Message loop of a QWidget owned by a QThread
I am developing a Qt application in Windows that captures global keyboard input. I am using WH_KEYBOARD which loads my DLL into every processes. When a key is pressed, the hook function in the DLL would SendMessage to a QWidget in a QThread inside the application. Problem is, how do I c开发者_JAVA百科reate a QWidget in QThread and start the message loop?
Well in two words, you can't. Widgets must be owned by the main thread and none of the GUI classes are can be multithreaded. You can though send signals across threads, i.e. the solution is to communicate from your DLL to a proxy class and then send queued signals to your widget in the main thread.
精彩评论