Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Update GUI from QThreadPool
Forum Updated to NodeBB v4.3 + New Features

Update GUI from QThreadPool

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arablau
    wrote on last edited by
    #1

    Hi Everyone,

    I am running a server with QThreadPool to manage worker threads. I have a GUI I'd like to update from inside a thread managed by the QThreadPool. I am having trouble figuring out how to connect the proper slots and signals so that my Runnable object can update my GUI on the main thread. How is this done?

    Thank you!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can't modify a GUI element from a worker thread. You can use e.g. a worker object that you will connect to your GUI before moving it to a different thread.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        euchkatzl
        wrote on last edited by
        #3

        First create a Slot in your GUI Object.
        Lets say you have an QWidget. Than you have to create a private slot like :

        private slots:
            void updateMyGui();    
        

        Then create a signal in your Runnable object.

        signals:
            void notifyGUI();
        

        And now when your create your Runnable object pass your widget as a pointer and simply connect your runnable signal tour your gui object slot :

        connect(this, SIGNAL(notifyGUI()), guiObjectPointer, SLOT(updateMyGui()));
        

        When you want to update your gui in your runnable you have to emit notifyGUI signal :

        emit notifyGUI();
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved