Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connect socket crash after close soket.
Qt 6.12 LTS is out! See what's new in the release blog

Connect socket crash after close soket.

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 4.1k 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.
  • 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
                      • Unsolved