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. Threads and signals
Qt 6.11 is out! See what's new in the release blog

Threads and signals

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 396 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.
  • A Offline
    A Offline
    alxdef
    wrote on last edited by
    #1

    Hi all!
    Sorry if my question is already solved but I can't found solution for me yet.

    I need to understand using of signals and slots across threads that is not in relation.

    For example, I have:

    1. Main GUI application named "main_ui";
    2. Main thread named "thread_main" that controls...
    3. ... set of threads (named "thread_#" respectively).

    "main_ui" contents a widget for logging of all application events.
    "main_ui" creates "thread_main" and they connected using slots well. "thread_main" is allowed to use "main_ui"'s log widget.
    "thread_#" created by "thread_main".
    How to connect "thread_#" and "main_ui" for use of "main_ui"'s log widget by "thread_#" directly?

    Creation order: main_ui => thread_main => thread_#

    jsulmJ JonBJ 2 Replies Last reply
    0
    • A alxdef

      @JonB, and how to connect main_ui slot with thread_#?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #7

      @alxdef said in Threads and signals:

      and how to connect main_ui slot with thread_#?

      Since you can connect signals to signals you can simply connect the signals from thread_# to corresponding signals in thread_main and connect slots in main_ui to signals from thread_main.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • A alxdef

        Hi all!
        Sorry if my question is already solved but I can't found solution for me yet.

        I need to understand using of signals and slots across threads that is not in relation.

        For example, I have:

        1. Main GUI application named "main_ui";
        2. Main thread named "thread_main" that controls...
        3. ... set of threads (named "thread_#" respectively).

        "main_ui" contents a widget for logging of all application events.
        "main_ui" creates "thread_main" and they connected using slots well. "thread_main" is allowed to use "main_ui"'s log widget.
        "thread_#" created by "thread_main".
        How to connect "thread_#" and "main_ui" for use of "main_ui"'s log widget by "thread_#" directly?

        Creation order: main_ui => thread_main => thread_#

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @alxdef said in Threads and signals:

        "thread_main" is allowed to use "main_ui"'s log widget.

        This is not going to work: only GUI thread is allowed to access UI!

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply
        0
        • jsulmJ jsulm

          @alxdef said in Threads and signals:

          "thread_main" is allowed to use "main_ui"'s log widget.

          This is not going to work: only GUI thread is allowed to access UI!

          A Offline
          A Offline
          alxdef
          wrote on last edited by
          #3

          @jsulm, I think I say incorrectly. I mean thread_# can send signal to main_ui with parameters for log widget.

          1 Reply Last reply
          0
          • A alxdef

            Hi all!
            Sorry if my question is already solved but I can't found solution for me yet.

            I need to understand using of signals and slots across threads that is not in relation.

            For example, I have:

            1. Main GUI application named "main_ui";
            2. Main thread named "thread_main" that controls...
            3. ... set of threads (named "thread_#" respectively).

            "main_ui" contents a widget for logging of all application events.
            "main_ui" creates "thread_main" and they connected using slots well. "thread_main" is allowed to use "main_ui"'s log widget.
            "thread_#" created by "thread_main".
            How to connect "thread_#" and "main_ui" for use of "main_ui"'s log widget by "thread_#" directly?

            Creation order: main_ui => thread_main => thread_#

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #4

            @alxdef
            There are several ways you could approach this, depending on what is "natural" to your code.

            First, your:

            "thread_main" is allowed to use "main_ui"'s log widget.

            Be careful about what you mean/implement for this. A thread should never access any widget in the UI thread. Depends what exactly you do here.

            That apart: when thread_main creates a thread_#, make it emit a signal. main_ui should have a slot on that signal, and receive whatever parameter necessary for it to do the required connect() on whatever signal it will receive in future from thread_# which notifies it to change its widget.

            Note that in all cases we have said threads must send signals to which main_ui is connected, and only main_ui accesses the widget.

            A 1 Reply Last reply
            0
            • JonBJ JonB

              @alxdef
              There are several ways you could approach this, depending on what is "natural" to your code.

              First, your:

              "thread_main" is allowed to use "main_ui"'s log widget.

              Be careful about what you mean/implement for this. A thread should never access any widget in the UI thread. Depends what exactly you do here.

              That apart: when thread_main creates a thread_#, make it emit a signal. main_ui should have a slot on that signal, and receive whatever parameter necessary for it to do the required connect() on whatever signal it will receive in future from thread_# which notifies it to change its widget.

              Note that in all cases we have said threads must send signals to which main_ui is connected, and only main_ui accesses the widget.

              A Offline
              A Offline
              alxdef
              wrote on last edited by
              #5

              @JonB, and how to connect main_ui slot with thread_#?

              JonBJ jsulmJ 2 Replies Last reply
              0
              • A alxdef

                @JonB, and how to connect main_ui slot with thread_#?

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #6

                @alxdef said in Threads and signals:

                @JonB, and how to connect main_ui slot with thread_#?

                Exactly as I wrote:

                That apart: when thread_main creates a thread_#, make it emit a signal. main_ui should have a slot on that signal, and receive whatever parameter necessary for it to do the required connect() on whatever signal it will receive in future from thread_# which notifies it to change its widget.

                EDIT
                Or you can indeed choose to "chain" signals as @jsulm writes below, using thread_main as an "intermediary". Both approaches are valid.

                1 Reply Last reply
                0
                • A alxdef

                  @JonB, and how to connect main_ui slot with thread_#?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @alxdef said in Threads and signals:

                  and how to connect main_ui slot with thread_#?

                  Since you can connect signals to signals you can simply connect the signals from thread_# to corresponding signals in thread_main and connect slots in main_ui to signals from thread_main.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2

                  • Login

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