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



  • 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.



  • 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.



  • 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?



  • 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



  • [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!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.