Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. gotnewmessage() signal does not emit after sendmessage() signal
Qt 6.11 is out! See what's new in the release blog

gotnewmessage() signal does not emit after sendmessage() signal

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
17 Posts 4 Posters 1.2k Views 1 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.
  • JonBJ JonB

    @fari35
    You're going to have show code for anyone to comment. In itself the fact that you changed how sendmessage() is sent/connected cannot affect something not being able to emit its own message.

    Try to show just the relevant bare-bones. We probably don't need to see the send message side, but do we do need to see (a) confirmation that the thread's slot is called from the send message and (b) how the thread does its emit gotnewmessage() and (c) how that emitted signal is connected to the slot which should act on it. Put in qDebug()s to prove what's going on!

    F Offline
    F Offline
    fari35
    wrote on last edited by
    #3
    This post is deleted!
    1 Reply Last reply
    0
    • JonBJ JonB

      @fari35
      You're going to have show code for anyone to comment. In itself the fact that you changed how sendmessage() is sent/connected cannot affect something not being able to emit its own message.

      Try to show just the relevant bare-bones. We probably don't need to see the send message side, but do we do need to see (a) confirmation that the thread's slot is called from the send message and (b) how the thread does its emit gotnewmessage() and (c) how that emitted signal is connected to the slot which should act on it. Put in qDebug()s to prove what's going on!

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

      @JonB I have now attached my whole code in the question. Can you please tell me what is wrong here?

      JonBJ 1 Reply Last reply
      0
      • F fari35

        @JonB I have now attached my whole code in the question. Can you please tell me what is wrong here?

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

        @fari35
        Too much for me, and I've done my bit. You should cut down the code to make it minimal and put qDebug() statements in to see what is/is not getting called.

        As a separate matter, get rid of old-style SIGNAL/SLOT() macros and always use new style. You presently have a mixture.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fari35
          wrote on last edited by
          #6

          @aha_1980 @kshegunov @Christian-Ehrlicher Do you have anyidea about this?

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

            I did not look what the code really does but tcpSocket is created in the wrong thread. You must create it inside run() so it's created in the new thread.

            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
            3
            • Christian EhrlicherC Christian Ehrlicher

              I did not look what the code really does but tcpSocket is created in the wrong thread. You must create it inside run() so it's created in the new thread.

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

              @Christian-Ehrlicher ok I have corrected that. Can you please tell me why gotnewmessage() is not working after sendmessage() signal is emmited from windows class?

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

                Hi,

                @fari35 said in gotnewmessage() signal does not emit after sendmessage() signal:

                class fserver : public QTcpServer,public threadobj

                Why the double heritage ?

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

                F 1 Reply Last reply
                1
                • SGaistS SGaist

                  Hi,

                  @fari35 said in gotnewmessage() signal does not emit after sendmessage() signal:

                  class fserver : public QTcpServer,public threadobj

                  Why the double heritage ?

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

                  @SGaist because I want to use the same object of fthread class in both the server and mainwindow class

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

                    This is not how it works. Please check the threaded fortune server example if you really want to use threads.

                    In any case, the way you use multiple inheritance is wrong.

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

                    F 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      This is not how it works. Please check the threaded fortune server example if you really want to use threads.

                      In any case, the way you use multiple inheritance is wrong.

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

                      @SGaist Actually that's not the problem. The problem is that it is emitting gotnewmessage() signal until I don't click send button in mainwindow class to emit sendmessage() signal, but once sendmessage() signal is emmitted gotnewmessage() signal doesn't emit

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

                        That will be part of the problem at some point because it makes your code messy.

                        In any case, you have an issue with the socket creation as it's not done in the correct thread.

                        You should really clean your implementation. It will make your code easier to manage and debug.

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

                        F 3 Replies Last reply
                        0
                        • SGaistS SGaist

                          That will be part of the problem at some point because it makes your code messy.

                          In any case, you have an issue with the socket creation as it's not done in the correct thread.

                          You should really clean your implementation. It will make your code easier to manage and debug.

                          F Offline
                          F Offline
                          fari35
                          wrote on last edited by
                          #14
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • SGaistS SGaist

                            That will be part of the problem at some point because it makes your code messy.

                            In any case, you have an issue with the socket creation as it's not done in the correct thread.

                            You should really clean your implementation. It will make your code easier to manage and debug.

                            F Offline
                            F Offline
                            fari35
                            wrote on last edited by
                            #15
                            This post is deleted!
                            1 Reply Last reply
                            0
                            • SGaistS SGaist

                              That will be part of the problem at some point because it makes your code messy.

                              In any case, you have an issue with the socket creation as it's not done in the correct thread.

                              You should really clean your implementation. It will make your code easier to manage and debug.

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

                              @SGaist ohh I just figured out once sendmessage() signal is emitted from mainwindow class then the readyread() function is not executed in fthread class. But why is that so?

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

                                Because there's no reason for that to happen. You just connected a signal to another signal.

                                Excuse me for being blunt but: your current code is a mess. Your architecture is wrong on several levels. You seem to want some kind of threaded server inside a GUI while also making it its own client but without any connection.

                                As I already suggested, if you really want to use threads (and you really don't at this stage), read the threaded fortune server example.

                                Keep things clearly separated. Have one server component, then build your GUI to use that component. Look for aggregation VS inheritance.

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

                                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