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. Boost Thread Qt Application
Forum Update on Monday, May 27th 2025

Boost Thread Qt Application

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 3.5k 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.
  • Q Offline
    Q Offline
    QTTman
    wrote on last edited by VRonin
    #1

    HI,all

    I'm try to make as described in this link(with code):
    http://wiki.qt.io/Boost_Thread_Qt_Application

    "So, let's call "Thread A" the thread that executes the public method of my library, that performs the three lines above. A new thread is created (the "boost" one), called "Thread B", that creates an instance of QApplication, my DialogProvider, and executes event loop of QApplication, everything in the same context. "Thread A" is blocked until I'm sure that my application is started, then returns.
    Some time later, a new thread, called "Thread C", wants to call a different public method that shows my widget. I just need to call
    app->showMyWidget(5,3.0);
    Of course, the two parameters are specified as example. "Thread C" posts a custom event (that carries on all information I need to create my widget) to QApplication event loop, that forwards it to my DialogProvider customEvent method. In that method (I'm in QApplication context, i.e. "Thread B"), I can create my widget and show it in the end, I just signal (using a QWaitCondition) that my widget is shown, so "Thread C" can return."

    How can I make communication in this example with "Thread A" and "myWidget" in both direction?

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

      Hi and welcome to devnet,

      What kind of communication do you have in mind ? What will you pass between the two threads ?

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

      Q 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        What kind of communication do you have in mind ? What will you pass between the two threads ?

        Q Offline
        Q Offline
        QTTman
        wrote on last edited by QTTman
        #3

        @SGaist
        Communication : I need pass QStrings. between main thread and second thread with QApp and widgets.

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

          How many times do you need to do that ?

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

          Q 1 Reply Last reply
          0
          • SGaistS SGaist

            How many times do you need to do that ?

            Q Offline
            Q Offline
            QTTman
            wrote on last edited by
            #5

            @SGaist Many times, depends on user action.
            the GUI thread sends data string to the main thread -> after doing the job, main thread sends back to GUI a result string.

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

              What is the main thread exactly ?

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

              Q 1 Reply Last reply
              0
              • SGaistS SGaist

                What is the main thread exactly ?

                Q Offline
                Q Offline
                QTTman
                wrote on last edited by
                #7

                @SGaist
                Programm "X" run my DLL . This is "main thread"
                In DLL I try to launch Qt GUI in different thread.

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @QTTman Does your main thread contain any QObjects? If so, you can use signals and slots to pass QStrings between the 2 threads.

                  Otherwise, your main thread can use QMetaObject::invokeMethod() with Qt::BlockingQueuedConnection to make a function run in your Qt thread and wait for a return value: http://doc.qt.io/qt-5/qmetaobject.html#invokeMethod

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  Q 1 Reply Last reply
                  1
                  • JKSHJ JKSH

                    @QTTman Does your main thread contain any QObjects? If so, you can use signals and slots to pass QStrings between the 2 threads.

                    Otherwise, your main thread can use QMetaObject::invokeMethod() with Qt::BlockingQueuedConnection to make a function run in your Qt thread and wait for a return value: http://doc.qt.io/qt-5/qmetaobject.html#invokeMethod

                    Q Offline
                    Q Offline
                    QTTman
                    wrote on last edited by
                    #9

                    @JKSH
                    If I'm right, I can't use any QObject in "main thread" before than QApp is initialized in the different thread.

                    JKSHJ 1 Reply Last reply
                    0
                    • Q QTTman

                      @JKSH
                      If I'm right, I can't use any QObject in "main thread" before than QApp is initialized in the different thread.

                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #10

                      @QTTman said in Boost Thread Qt Application:

                      If I'm right, I can't use any QObject in "main thread" before than QApp is initialized in the different thread.

                      Yes, you are right.

                      So, you can use QMetaObject::invokeMethod()

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      1 Reply Last reply
                      1

                      • Login

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