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. Socket notifiers cannot send from another thread
Forum Updated to NodeBB v4.3 + New Features

Socket notifiers cannot send from another thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 372 Views 2 Watching
  • 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.
  • R RobertSommer
    1 May 2025, 12:37

    Hello,
    I have a big problem with threads.

    I have a Terminal class that inherits from a CScada class (C++ DLL).

    The CScada class has a Receive function. This receives data that I have to analyze and pass on to the client via a socket interface.

    RClient ---- Socket ---- Terminal(CScada) ----- CustomApp
    override Receive function.

    I would probably have to send a SendMessage from the Receive function to the terminal, then from there the response via socket to the client. How should I do this?

    Thanks for tipps in advance. QT 5.6.X version

    C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 1 May 2025, 12:50 last edited by
    #2

    @RobertSommer said in Socket notifiers cannot send from another thread:

    How should I do this?

    How should we know? There is no code...
    Use signals and slots to make sure the function call is made in the correct thread.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    R 1 Reply Last reply 2 May 2025, 06:06
    1
    • R RobertSommer
      1 May 2025, 12:37

      Hello,
      I have a big problem with threads.

      I have a Terminal class that inherits from a CScada class (C++ DLL).

      The CScada class has a Receive function. This receives data that I have to analyze and pass on to the client via a socket interface.

      RClient ---- Socket ---- Terminal(CScada) ----- CustomApp
      override Receive function.

      I would probably have to send a SendMessage from the Receive function to the terminal, then from there the response via socket to the client. How should I do this?

      Thanks for tipps in advance. QT 5.6.X version

      A Offline
      A Offline
      Axel Spoerl
      Moderators
      wrote on 1 May 2025, 14:28 last edited by
      #3

      @RobertSommer said in Socket notifiers cannot send from another thread:

      QT 5.6.X version

      Just out of interest: Why such an antique version?

      Software Engineer
      The Qt Company, Oslo

      R 1 Reply Last reply 2 May 2025, 06:19
      0
      • C Christian Ehrlicher
        1 May 2025, 12:50

        @RobertSommer said in Socket notifiers cannot send from another thread:

        How should I do this?

        How should we know? There is no code...
        Use signals and slots to make sure the function call is made in the correct thread.

        R Offline
        R Offline
        RobertSommer
        wrote on 2 May 2025, 06:06 last edited by
        #4

        @Christian-Ehrlicher said in Socket notifiers cannot send from another thread:

        How should we know? There is no code...
        Use signals and slots to make sure the function call is made in the correct thread.

        I am a beginner and do not know how to implement this.
        RClient ---- Socket ---- Terminal(CScada) ----- CustomApp
        override Receive function.

        Have you understood the problem?
        I have a Console application, class Terminal that inherits from CScada. This has a receive function in it, when data arrives I have to read and analyze it, then send a response via socket to the client. Then comes , not possible from another thread.

        connect (pointer_to_ink, &Ink::ready, this, &Controller(Terminal)::correspondingSlot)
        
        //Instance:    pointer_to_ink  
         // Event:   ready
        //then call   --> correspondingSlot from my controller(Terminal)
        

        I don't have two objects now, just the terminal.
        How can I solve this?

        1 Reply Last reply
        0
        • A Axel Spoerl
          1 May 2025, 14:28

          @RobertSommer said in Socket notifiers cannot send from another thread:

          QT 5.6.X version

          Just out of interest: Why such an antique version?

          R Offline
          R Offline
          RobertSommer
          wrote on 2 May 2025, 06:19 last edited by
          #5

          @Axel-Spoerl said in Socket notifiers cannot send from another thread:

          Just out of interest: Why such an antique version?

          I am a beginner and a colleague gave me this to test whether QT is better than C#.

          What is the current free version? And where can I get it?

          P 1 Reply Last reply 2 May 2025, 20:34
          0
          • A Offline
            A Offline
            Axel Spoerl
            Moderators
            wrote on 2 May 2025, 08:03 last edited by
            #6

            https://www.qt.io/download-dev

            Software Engineer
            The Qt Company, Oslo

            1 Reply Last reply
            0
            • R RobertSommer
              2 May 2025, 06:19

              @Axel-Spoerl said in Socket notifiers cannot send from another thread:

              Just out of interest: Why such an antique version?

              I am a beginner and a colleague gave me this to test whether QT is better than C#.

              What is the current free version? And where can I get it?

              P Offline
              P Offline
              Pl45m4
              wrote on 2 May 2025, 20:34 last edited by Pl45m4 5 Feb 2025, 20:39
              #7

              @RobertSommer said in Socket notifiers cannot send from another thread:

              whether QT is better than C#

              Qt is not a programming language.
              You can't compare these two.
              Is a banana better than a bicycle?

              You can compare C++ with C#
              Or WinForms/WPF with Qt.

              not possible from another thread

              At least show what your setup looks like... from the connection only we can't tell what you are doing (wrong).


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              R C 2 Replies Last reply 3 May 2025, 14:40
              0
              • P Pl45m4
                2 May 2025, 20:34

                @RobertSommer said in Socket notifiers cannot send from another thread:

                whether QT is better than C#

                Qt is not a programming language.
                You can't compare these two.
                Is a banana better than a bicycle?

                You can compare C++ with C#
                Or WinForms/WPF with Qt.

                not possible from another thread

                At least show what your setup looks like... from the connection only we can't tell what you are doing (wrong).

                R Offline
                R Offline
                RobertSommer
                wrote on 3 May 2025, 14:40 last edited by
                #8

                @Pl45m4
                ok.

                Have you understood my problem?

                connect (pointer_to_ink, &Ink::ready, this, &Controller(Terminal)::correspondingSlot)
                

                like this, is not possible, because I'm inside the Controller(Terminal) class.
                The class inherits from CScada, which has a ReceiveData function. Event based. This is called when changes are made.

                I check the data and want to send it to the client via a socket interface.
                When I call the SendtoSocketClient function, not allowed comes from another thread. The problem.

                Maybe I need to implement a SendMessage logic. Can you show me how this could work?
                A connect via signal and slot is not possible, as I am in the same class.

                1 Reply Last reply
                0
                • P Pl45m4
                  2 May 2025, 20:34

                  @RobertSommer said in Socket notifiers cannot send from another thread:

                  whether QT is better than C#

                  Qt is not a programming language.
                  You can't compare these two.
                  Is a banana better than a bicycle?

                  You can compare C++ with C#
                  Or WinForms/WPF with Qt.

                  not possible from another thread

                  At least show what your setup looks like... from the connection only we can't tell what you are doing (wrong).

                  C Offline
                  C Offline
                  CassD
                  wrote on 3 May 2025, 14:58 last edited by CassD 5 Mar 2025, 15:28
                  #9

                  @Pl45m4 said in Socket notifiers cannot send from another thread:

                  @RobertSommer said in Socket notifiers cannot send from another thread:

                  whether QT is better than C#

                  Qt is not a programming language.
                  You can't compare these two.

                  I just guess what OP says is to compare Qt and .NET ...Amalgams between C# and .NET are common as C# is tightly coupled to .NET (and those amalgams seem to be even more common for Java and JDK) by people who eigher don't bother make the difference, or downright don't even know about.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Axel Spoerl
                    Moderators
                    wrote on 3 May 2025, 15:10 last edited by
                    #10

                    @RobertSommer
                    Nobody can tell you why the code doesn’t work, because we don’t know what the terminal class is. You need to boil the issue down to a minimal compilable reproducer, small enough to post it here, directly, using the </> code tags, to get the format right. Please also specify what exactly “is not possible” means: Does the connect statement not compile? Does it compile but the connection goes wrong? Is a warning printed? A compile error?

                    Software Engineer
                    The Qt Company, Oslo

                    R 1 Reply Last reply 4 May 2025, 14:10
                    0
                    • A Axel Spoerl
                      3 May 2025, 15:10

                      @RobertSommer
                      Nobody can tell you why the code doesn’t work, because we don’t know what the terminal class is. You need to boil the issue down to a minimal compilable reproducer, small enough to post it here, directly, using the </> code tags, to get the format right. Please also specify what exactly “is not possible” means: Does the connect statement not compile? Does it compile but the connection goes wrong? Is a warning printed? A compile error?

                      R Offline
                      R Offline
                      RobertSommer
                      wrote on 4 May 2025, 14:10 last edited by
                      #11

                      @Axel-Spoerl said in Socket notifiers cannot send from another thread:

                      @RobertSommer
                      Nobody can tell you why the code doesn’t work,

                      Sure.
                      Can a signal be set by an inherited receive function, event?
                      If so, how? I don't have a code because I don't know.

                      P 1 Reply Last reply 4 May 2025, 19:55
                      0
                      • R RobertSommer
                        4 May 2025, 14:10

                        @Axel-Spoerl said in Socket notifiers cannot send from another thread:

                        @RobertSommer
                        Nobody can tell you why the code doesn’t work,

                        Sure.
                        Can a signal be set by an inherited receive function, event?
                        If so, how? I don't have a code because I don't know.

                        P Offline
                        P Offline
                        Pl45m4
                        wrote on 4 May 2025, 19:55 last edited by
                        #12

                        @RobertSommer said in Socket notifiers cannot send from another thread:

                        Can a signal be set by an inherited receive function, event?

                        Set?!
                        You can emit a signal wherever you can also call a function.
                        But depends on your logic if that makes sense.


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        1 Reply Last reply
                        0

                        11/12

                        4 May 2025, 14:10

                        • Login

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