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. readyread() signal doesn't emit after sendmessage() signal on pushbutton
Forum Updated to NodeBB v4.3 + New Features

readyread() signal doesn't emit after sendmessage() signal on pushbutton

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 8 Posters 3.1k Views 4 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.
  • F fari35

    @mrjj Yes, I have checked right nnow the slots are only called once

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #12

    @fari35
    I have told you before to put qDebug() statements in. You are supposed to do more investigation yourself and report the exact problem rather than just keep throwing your whole code at the community for answer....

    F 1 Reply Last reply
    0
    • JonBJ JonB

      @fari35
      I have told you before to put qDebug() statements in. You are supposed to do more investigation yourself and report the exact problem rather than just keep throwing your whole code at the community for answer....

      F Offline
      F Offline
      fari35
      wrote on last edited by fari35
      #13

      @JonB I didn't attch the whole code initially but after they asked for it , I've attached my whole code, but now I have cut it short. the problem I'm getting is that readyread() siggnal is not emitting after send button is pressed. Before pressing the send button it emits even if the client sends 10 messages it emits 10 times but as soon as the send button is pressed it stops emitting

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #14

        The code still does not show where the QTcpSocket is created - and when it's like I guess you implemented it, it's still created in the wrong thread. Please provide a minimal, compilable example!

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

        F 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          The code still does not show where the QTcpSocket is created - and when it's like I guess you implemented it, it's still created in the wrong thread. Please provide a minimal, compilable example!

          F Offline
          F Offline
          fari35
          wrote on last edited by fari35
          #15

          @Christian-Ehrlicher here is the code for run() where QTcpSocket is created:

          void fthread::run()
          {
          
          
              tcpSocket = new QTcpSocket();
          
              if (!tcpSocket->setSocketDescriptor(socketDescriptor)) {
                  emit error(tcpSocket->error());
                  return;
              }
          
              connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readyRead()));
          
              connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
          
              exec();
          
          }
          
          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #16

            @fari35 said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

            connect( this, SIGNAL(sendmessage(QString)),thread_obj, SLOT(sendmessage(QString)));

            As I said - the function sendmessage(QString) is executed in the main thread. Please read the docs about QThread or don't use QThread at all when you don't know the basics. There is no reason to use threads at all...

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

            F 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @fari35 said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

              connect( this, SIGNAL(sendmessage(QString)),thread_obj, SLOT(sendmessage(QString)));

              As I said - the function sendmessage(QString) is executed in the main thread. Please read the docs about QThread or don't use QThread at all when you don't know the basics. There is no reason to use threads at all...

              F Offline
              F Offline
              fari35
              wrote on last edited by fari35
              #17

              @Christian-Ehrlicher Actually I need to make a multi threaded server for my project and I'm using Qt for that. I want to send the message to all the clients who have been assigned a separate thread, Can you please tell me how can I do that because I'm not getting it.

              JonBJ 1 Reply Last reply
              0
              • F fari35

                @Christian-Ehrlicher Actually I need to make a multi threaded server for my project and I'm using Qt for that. I want to send the message to all the clients who have been assigned a separate thread, Can you please tell me how can I do that because I'm not getting it.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #18

                @fari35
                What is it you need beyond the Threaded Fortune Server Example ? How much are you based on that?

                F 1 Reply Last reply
                0
                • JonBJ JonB

                  @fari35
                  What is it you need beyond the Threaded Fortune Server Example ? How much are you based on that?

                  F Offline
                  F Offline
                  fari35
                  wrote on last edited by
                  #19

                  @JonB In this example it's not shown how to send the message to the client if the signal is emitted from the main thread like here I'm making a UI for the server so I want to send the message to the client as soon as the send button is clicked, but I don't know how to do it. I'm not even getting help from anywhere.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #20

                    Again: if you want to use thread (for whatever reason, maybe just to show that you're a famous programmer...), make sure you understand what you're doing and read the documentation and examples:

                    "It is important to remember that a QThread instance lives in the old thread that instantiated it, not in the new thread that calls run(). This means that all of QThread's queued slots and invoked methods will execute in the old thread. Thus, a developer who wishes to invoke slots in the new thread must use the worker-object approach; new slots should not be implemented directly into a subclassed QThread."

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

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

                      @fari35: To clarify the documentation quoted by @Christian-Ehrlicher's: Do not implement any slots in fthread. Instead, implement your slot in a separate QObject. Create that object together with tcpSocket.

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

                      F 1 Reply Last reply
                      2
                      • JKSHJ JKSH

                        @fari35: To clarify the documentation quoted by @Christian-Ehrlicher's: Do not implement any slots in fthread. Instead, implement your slot in a separate QObject. Create that object together with tcpSocket.

                        F Offline
                        F Offline
                        fari35
                        wrote on last edited by fari35
                        #22

                        @JKSH @Christian-Ehrlicher If I implement the slot in a separate Qobject then how can I send the data from that class as my TcpSocket is created in fthread class?
                        My issue is same as this one :
                        https://stackoverflow.com/questions/35927165/qt-multi-threaded-multi-client-tcp-server-socket-write-issue/65750692#65750692

                        JKSHJ Christian EhrlicherC 2 Replies Last reply
                        0
                        • F fari35

                          @JKSH @Christian-Ehrlicher If I implement the slot in a separate Qobject then how can I send the data from that class as my TcpSocket is created in fthread class?
                          My issue is same as this one :
                          https://stackoverflow.com/questions/35927165/qt-multi-threaded-multi-client-tcp-server-socket-write-issue/65750692#65750692

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

                          @fari35 said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

                          If I implement the slot in a separate Qobject then how can I send the data from that class as my TcpSocket is created in fthread class?

                          Let's take a step back.

                          Imagine that your server only needs to communicate with one client. Imagine that you have no threads; your QTcpSocket is in the main thread. How can you send data from a QObject to the socket?

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

                          F 1 Reply Last reply
                          0
                          • JKSHJ JKSH

                            @fari35 said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

                            If I implement the slot in a separate Qobject then how can I send the data from that class as my TcpSocket is created in fthread class?

                            Let's take a step back.

                            Imagine that your server only needs to communicate with one client. Imagine that you have no threads; your QTcpSocket is in the main thread. How can you send data from a QObject to the socket?

                            F Offline
                            F Offline
                            fari35
                            wrote on last edited by
                            #24

                            @JKSH I'll simply create a QTcpSocket and then after initializing it I'll send the data to the client

                            1 Reply Last reply
                            0
                            • F fari35

                              @JKSH @Christian-Ehrlicher If I implement the slot in a separate Qobject then how can I send the data from that class as my TcpSocket is created in fthread class?
                              My issue is same as this one :
                              https://stackoverflow.com/questions/35927165/qt-multi-threaded-multi-client-tcp-server-socket-write-issue/65750692#65750692

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #25

                              @fari35 said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

                              If I implement the slot in a separate Qobject then how can I send the data from that class as my TcpSocket is created in fthread class?

                              Did you actually ook at least once in the documentation. Hint: there is an example which describes how to properly create an object living in another thread and how to connect signals from/to them.

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

                              A 1 Reply Last reply
                              0
                              • Christian EhrlicherC Christian Ehrlicher

                                @fari35 said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

                                If I implement the slot in a separate Qobject then how can I send the data from that class as my TcpSocket is created in fthread class?

                                Did you actually ook at least once in the documentation. Hint: there is an example which describes how to properly create an object living in another thread and how to connect signals from/to them.

                                A Offline
                                A Offline
                                Anonymous_Banned275
                                wrote on last edited by
                                #26

                                @Christian-Ehrlicher said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

                                Did you actually ook at least once in the documentation.

                                Perhaps if you throttle DOWN your nagging attitude a little ?
                                It seldom helps resolving TECHNICAL issue.
                                There seems to be few people perpetuating similar format recently , I am not particularly picking you.
                                Just saying.

                                1 Reply Last reply
                                -3
                                • Christian EhrlicherC Offline
                                  Christian EhrlicherC Offline
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #27

                                  @AnneRanch said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

                                  Perhaps if you throttle DOWN your nagging attitude a little ?

                                  I simply don't understand how someone can ignore our hints the whole time and asking the same stuff over and over again. I already said in my first post here what's wrong and that threading is not that easy. So if it's not easy and I (ask someone who wants to learn) would read the documentation and study the examples to see how all is going.

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

                                  A 1 Reply Last reply
                                  2
                                  • Christian EhrlicherC Christian Ehrlicher

                                    @AnneRanch said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

                                    Perhaps if you throttle DOWN your nagging attitude a little ?

                                    I simply don't understand how someone can ignore our hints the whole time and asking the same stuff over and over again. I already said in my first post here what's wrong and that threading is not that easy. So if it's not easy and I (ask someone who wants to learn) would read the documentation and study the examples to see how all is going.

                                    A Offline
                                    A Offline
                                    Anonymous_Banned275
                                    wrote on last edited by
                                    #28

                                    @Christian-Ehrlicher said in readyread() signal doesn't emit after sendmessage() signal on pushbutton:

                                    don't understand how someone can ignore our hints

                                    I simply do not want to get into social analysis why people, in general , should be chastised, in any format , for their not choosing / following " our hints" or our opinions.

                                    If you have a issue with that - you do have a choice NOT to participate - if that bothers you that much.

                                    Cheers

                                    PS
                                    I used to call people who do not respond or follow advises "shooting star" . They generally only post once and then find a more rewarding means to entertain themselves .

                                    End of rant

                                    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