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] Qt GUI for my multi-threaded console app on Linux?
Forum Update on Monday, May 27th 2025

[SOLVED] Qt GUI for my multi-threaded console app on Linux?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 6.0k Views
  • 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.
  • V Offline
    V Offline
    vincegata
    wrote on 22 Apr 2012, 16:19 last edited by
    #1

    Hello,

    I have a multi-threaded command line application written in C++ on Ubuntu that downloads data from a remote server over tcp sockets in one thread (receive_thread), processes those data in another thread (process_thread), and sends results to another remote server in a third thread (post_thread). Download, process, and post are done asynchronously and in real time. Each thread outputs data and error messages into stdout and stderr, so the messages from all threads are intermixed in the shell.

    I want to develop a GUI that will display all those messages in separate windows, I will also need to input data. I see it as a parent window that launches multiple non-modal dialog boxes, each dialog displaying messages from from each thread. I want to see the messages from all threads at the same time, I also want to be able to spread dialog boxes across multiple monitors.

    Is Qt up to the task?

    I'd appreciate your input. Thank you.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      d2uriel
      wrote on 22 Apr 2012, 17:45 last edited by
      #2

      Of course Qt is up to the task. You should be able to easily create a UI for you app either manually or using QtCreator. You can read about threading in Qt "here":http://qt-project.org/doc/qt-4.8/threads.html. Good luck.

      "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vincegata
        wrote on 22 Apr 2012, 18:45 last edited by
        #3

        Let me put it the other way. I already have a multi-threaded console application written in C++ for Linux. I use Linux (POSIX) tools for multi threading - pthread. My app is:

        1. Parent thread, launches other three threads.
        2. receive thread.
        3. process thread.
        4. send thread.

        I need GUI with

        1. Parent window with three buttons that will launch three non-modal dialog boxes. It will also take some input.
        2. Non-modal dialog box that will display messages from thread 2.
        3. Non-modal dialog box that will display messages from thread 3.
        4. Non-modal dialog box that will display messages from thread 4.

        Is it possible to implement such GUI in Qt, is it thread safe?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on 22 Apr 2012, 23:46 last edited by
          #4

          This should work fine with Qt!

          Qt provides a QThread class to manage threads. As with all GUI frameworks that I am aware of, you can't access GUI widgets directly from any thread, except for the "main" thread (i.e. the thread that processes the event loop). That's no different with Qt. But Qt's "signals and slots":http://qt-project.org/doc/qt-4.8/signalsandslots.html concept provides a very elegant solution: Simply make your threads (derived from QThread) emit signals to "post" status updates (e.g. log messages). The Dialog box (derived from QDialog) will then process the status updates with a suitable slot function. Now you only need to connect the thread's signal to the dialog box' slot. As these objects live in different threads, use a "queued":http://qt-project.org/doc/qt-4.8/qt.html#ConnectionType-enum connection! This makes sure the slot is executed in the context of the "main" thread and can access/update the GUI widgets safely. Of course you can have multiple threads and multiple dialog boxes at the same time. And they can be connected as needed. I have implemented several applications this way :)

          See also:
          http://doc.trolltech.com/main-snapshot/threads-qobject.html

          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
          • V Offline
            V Offline
            vincegata
            wrote on 23 Apr 2012, 00:24 last edited by
            #5

            [quote author="MuldeR" date="1335138403"]
            Qt provides a QThread class to manage threads. As with all GUI frameworks that I am aware of, you can't access GUI widgets directly from any thread, except for the "main" thread (i.e. the thread that processes the event loop). [/quote] -- Ohhh, I see.

            I got it, I might have more detailed questions later. Thanks for your post!

            1 Reply Last reply
            0

            1/5

            22 Apr 2012, 16:19

            • Login

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