psykhi
psykhi

Reputation: 2981

Render off screen widget in a separate thread Qt

The application I'm working on is made of many C threads communicating together via messages (0mq). One of these threads is handling the display and should render off screen a widget in order to communicate its "screenshot" to other threads of the application.

The thing is that in order to paint a widget, you need to place it in a QApplication and call the exec() method of the QApplication, which is essentially a loop. So my thread is then completely stuck and can't communicate with the outside world anymore since it's in the exec() method.

Is there a way I can launch the QApplication in a separate thread and communicate with it so my display thread doesn't get stuck? Or is there at least a way to do what I want to do with Qt?

Thanks a lot !

Edit: This application will eventually be a Qt Embedded Application

Update Basically, my question is : how to start a QApplication in a separate thread from my C code and communicate with it?

Upvotes: 0

Views: 947

Answers (2)

psykhi
psykhi

Reputation: 2981

I ended up creating a separate thread for the QApplication main event loop (exec()) and used 0mq sockets to communicate with it from the rest of my application.

Upvotes: 1

ixSci
ixSci

Reputation: 13698

I don't understand what do you mean by "paint a widget". But be aware: QWidget is a part of GUI and GUI parts should be touched by Main(UI) thread only. It is a rule you can't change. Moreover QApplication works on Main thread only since QApplication is the main part of the GUI itself. You can post messages to QAppplication by using global qApp object(you need to include QApplication for it) and sendEvent() or postEvent() methods.

Also I'd suggest you to generate QImage with whatever data you have and propagate it via aforementioned event mechanism to the widget you need. But, obviously, I don't know what you really need.

Upvotes: 0

Related Questions