Connect socket crash after close soket.
-
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
-
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.
-
@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
-
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 ?
-
@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.
-
@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()));
-
@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.
-
@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