PDA

View Full Version : How to show a QWidget from a different thread without using signal?



topher
27th February 2008, 02:36
I need to show some widgets from the second thread. These codes do not exist in a subclass of QObject, so I cannot use signal and slot to accomplish it. I was thinking about using events but I didn't see any suitable event. I've also tried to use QMetaObject::invokeMethod() but it didn't work either. It returns true but nothing happens.

Could anyone give me some suggestions?
Thanks!

marcel
27th February 2008, 02:40
You can use user events. Subclass QEvent and give it a suitable ID.
You can also attach custom data to user events.

topher
27th February 2008, 03:07
I'm wondering if it is possible to use something pre-existed in QT framework for this.
The reason I want to avoid user events is that it implies reimplementation of event handler for this event. It seems to be a huge work when there are a lot of widgets. Am I right on this?

wysota
27th February 2008, 08:01
If you want something "pre-existed" then use signals :)

If you need it for many widgets, I suggest you implement a special object that will be calling show() for you on desired widgets when it receives the custom event. This way you'll only have to implement the solution for one object and it will work for all of them.