Connect socket crash after close soket.
-
Did you properly allocate socket ?
-
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 ?
-
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 ?
@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); -
@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.
-
@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.
@Christian-Ehrlicher I do not destroy the socket object when logout, just disconnect.
-
@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()));
-
@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()));
@Christian-Ehrlicher According to SGaist's reply, this sentence has been removed.Then I will close this question and ask another question again.
-
Please show a fully working example - we don't know what you're doing when you only post misc fragments of your code.
-
Please show a fully working example - we don't know what you're doing when you only post misc fragments of your code.
@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