Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can you implement dialogs on different threads?



  • Hi, I have two dialogs which one is a sender dialog and the other is a receiver dialog. I wish to implement them on different threads but I'm not sure how to do it. From what I learn, thread can only be implemented on a QObject but not QDialog. Is there any suggestion on how to do so?


  • Lifetime Qt Champion

    @Christina123

    Hi
    Running something in a thread in the same app, it's not like 2 computers much.

    You could run same app twice ? and talk between them ?

    But that you wont use signals for.

    So what is the task / assignment ?

    you can run a qobject in other thread and talk to it from main.

    see different samples here
    https://github.com/DeiVadder/QtThreadExample


  • Lifetime Qt Champion

    Hi
    Only the main thread can use QWidgets.
    So a dialog cannot live in another thread in any way.

    But why did you want that in the first place ?

    Maybe the goal can be reached in other ways.

    Often one will run heavy code in its own thread. and then use signals to send info back to the
    main thread / the GUI.



  • @mrjj Hi, thank you for your reply. Yes, I fully understand your point so that is the reason why I get stuck here. What I want to simulate is two different computers which one is sending signal (Sender) and the other is receiving signal (Receiver). So, obviously they are supposed to run on two different threads. But, since I create them as dialogs, I could not put them on threads apart from main thread. To implement my idea, is it that I should create QObject class and instantiate the dialog as a member of it?


  • Lifetime Qt Champion

    @Christina123

    Hi
    Running something in a thread in the same app, it's not like 2 computers much.

    You could run same app twice ? and talk between them ?

    But that you wont use signals for.

    So what is the task / assignment ?

    you can run a qobject in other thread and talk to it from main.

    see different samples here
    https://github.com/DeiVadder/QtThreadExample



  • Thank you! The website clears things up for me :)


Log in to reply