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. [Solved] How do I make a cross-threaded update on a widget?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How do I make a cross-threaded update on a widget?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.4k 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.
  • P Offline
    P Offline
    primem0ver
    wrote on last edited by
    #1

    I am writing a server using Qt's networking and GUI interface. I have a read-only QTextEdit widget that serves as a visible log for server events. This includes events regarding new connections which are handled on a separate thread (one for each connection). I want to send information about what is happening on the connection to the log text. (Which means appending text to the log from another thread). It also needs to update an actual log file.

    I have done this kind of thing in .NET (cross-thread updates to controls) but I am still relatively new to Qt.
    How would I go about doing this?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I suggest creating a slot that would append the text (in main thread). Then, from your server threads, connect to that slot using Qt::QueuedConnection mode. This way you can be cartain that you UI will not be blocked, and you do not need to worry about mutexes, locking, etc.

      (Z(:^

      1 Reply Last reply
      0
      • P Offline
        P Offline
        primem0ver
        wrote on last edited by
        #3

        Thanks. I will try that out but maybe I missed something. What would be the connecting signal that triggered the slot? Perhaps I would need to make my own? If so, I suppose the text needing to be sent would be the argument passed (from the signal to the slot?)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          Take a look on "Mandelbrot Example":http://qt-project.org/doc/qt-5/qtcore-mandelbrot-example.html

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on last edited by
            #5

            [quote author="primem0ver" date="1408252568"]Thanks. I will try that out but maybe I missed something. What would be the connecting signal that triggered the slot? Perhaps I would need to make my own? If so, I suppose the text needing to be sent would be the argument passed (from the signal to the slot?)[/quote]

            Yes, you would add a suitable Signal to your Thread/Worker class, e.g. updateAvailable(QString), and a corresponding Slot to the GUI class, e.g. handleUpdate(QString). Then you create a queued connection between the GUI object and each Thread/Worker object. And each time something interesting has happened in the Thread/Worker object it emits the signal.

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            1 Reply Last reply
            0
            • P Offline
              P Offline
              primem0ver
              wrote on last edited by
              #6

              Thanks everyone. I appreciate the help. I will mark this as solved as it is going to take some time before I can compile and see the result.

              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