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. Connect socket crash after close soket.

Connect socket crash after close soket.

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

    The first time the connection is normal, it will not work after closing.

    close:

    connect(socket,SIGNAL(disconnected()),socket,SLOT(deleteLater()));
    socket->disconnectFromHost();
    

    connect:

    socket->connectToHost(host, port); //crash line
    

    error:

    libc: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xbcf9f850
    

    env:

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

      Hi,

      You connected the deleteLater slot to the disconnected signal. Right after that you call disconnectFromHost and at some later point in time you use the exact same object which has been deleted in between.

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

      S 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        You connected the deleteLater slot to the disconnected signal. Right after that you call disconnectFromHost and at some later point in time you use the exact same object which has been deleted in between.

        S Offline
        S Offline
        senmx
        wrote on last edited by senmx
        #3

        @SGaist Thanks. I removed

        connect(socket,SIGNAL(disconnected()),socket,SLOT(deleteLater()));
        

        But occured the same error in some else line. Can't locate the code line, is there a way to get detailed errors from libc.so to the app code line?

        F libc    : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1 in tid 10601 (QtThread), pid 10527
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you properly allocate socket ?

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

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            Did you properly allocate socket ?

            S Offline
            S Offline
            senmx
            wrote on last edited by
            #5

            @SGaist The socket object is not destroyed when it is closed, and the socket object is still the original when it is reconnected. It would be nice if can locate the code line.

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

              You are using deleteLater once it's called, the object will be deleted and you will have a dangling pointer.

              In any case, you do not answer my question: is socket properly allocated before you use it ?

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

              S 1 Reply Last reply
              0
              • SGaistS SGaist

                You are using deleteLater once it's called, the object will be deleted and you will have a dangling pointer.

                In any case, you do not answer my question: is socket properly allocated before you use it ?

                S Offline
                S Offline
                senmx
                wrote on last edited by
                #7

                @SGaist Does it mean this, only new once when the app starts.

                socket = new QTcpSocket();
                timeoutTimer = new QTimer();
                timeoutTimer->setSingleShot(true);
                connect(timeoutTimer, &QTimer::timeout, this, &SocketManager::connectionTimeout);
                connect(socket, &QTcpSocket::disconnected, this, &SocketManager::disconnected);
                
                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @senmx said in Connect socket crash after close soket.:

                  only new once when the app starts.

                  But when you delete it during the runtime then you will get a dangling pointer as @SGaist already pointed out.

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

                  S 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @senmx said in Connect socket crash after close soket.:

                    only new once when the app starts.

                    But when you delete it during the runtime then you will get a dangling pointer as @SGaist already pointed out.

                    S Offline
                    S Offline
                    senmx
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher I do not destroy the socket object when logout, just disconnect.

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

                      @senmx said in Connect socket crash after close soket.:

                      just disconnect.

                      Not according to your (incomplete) code snippet:

                      connect(socket,SIGNAL(disconnected()),socket,SLOT(deleteLater()));

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

                      S 1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @senmx said in Connect socket crash after close soket.:

                        just disconnect.

                        Not according to your (incomplete) code snippet:

                        connect(socket,SIGNAL(disconnected()),socket,SLOT(deleteLater()));

                        S Offline
                        S Offline
                        senmx
                        wrote on last edited by senmx
                        #11

                        @Christian-Ehrlicher According to SGaist's reply, this sentence has been removed.Then I will close this question and ask another question again.

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

                          Please show a fully working example - we don't know what you're doing when you only post misc fragments of your code.

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

                          S 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            Please show a fully working example - we don't know what you're doing when you only post misc fragments of your code.

                            S Offline
                            S Offline
                            senmx
                            wrote on last edited by
                            #13

                            @Christian-Ehrlicher Thanks. I asked another question, please take a look.
                            https://forum.qt.io/topic/122204/how-to-get-detailed-errors-from-libc-so-to-the-app-code-line

                            1 Reply Last reply
                            0

                            • Login

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