PDA

View Full Version : Build GUI-Elements from QThread



StarShaper
19th February 2012, 13:49
Hi,

I wonder if it is possible to create GUI-Elements, like a Window (QWidget) from a QThread. I don't wan't to interact with the Window from the main() Thread. I just want to create a window from a QThread. I already checked this out and it seems to work. My window gets build from a method of my QThread and the ctr() of the Widget shows that it is the same thread id, like my QThread.

mentalmushroom
22nd February 2012, 10:49
As far as I know, you can create widgets from any thread, but you should access them from the same thread they belong to. However, it seems like you do something strange. I can't imagine the case when you need that.

StarShaper
22nd February 2012, 23:08
Doesn't matter. I read in the Qt docs that you shouldn't create GUI elements from other threads, than the main thread!

It may work, but it is undefined behaviour.

wysota
24th February 2012, 09:46
Hi,

I wonder if it is possible to create GUI-Elements, like a Window (QWidget) from a QThread. I don't wan't to interact with the Window from the main() Thread. I just want to create a window from a QThread. I already checked this out and it seems to work. My window gets build from a method of my QThread and the ctr() of the Widget shows that it is the same thread id, like my QThread.

That's probably because your QThread object lives in the main thread so your gui is also built from the main thread and not the worker thread.

What is the purpose of creating widgets from a worker thread? Is your widget constructor so expensive you can't afford to call it from the main thread?