Results 1 to 4 of 4

Thread: Build GUI-Elements from QThread

  1. #1
    Join Date
    Jan 2012
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Build GUI-Elements from QThread

    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.

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows
    Thanks
    17
    Thanked 27 Times in 24 Posts

    Default Re: Build GUI-Elements from QThread

    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.

  3. #3
    Join Date
    Jan 2012
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Build GUI-Elements from QThread

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Build GUI-Elements from QThread

    Quote Originally Posted by StarShaper View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 4th October 2011, 00:04
  2. Ui Elements (QLineEdit) + QML
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2010, 17:04
  3. Error on build..QThread class
    By freekill in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2009, 06:45
  4. elements not updated
    By danesh in forum Qt Programming
    Replies: 2
    Last Post: 2nd April 2009, 09:35
  5. Elements out of Range!!
    By Kapil in forum Newbie
    Replies: 9
    Last Post: 3rd April 2006, 11:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.