QSqlsocket crash when deleting
Hi,
I'm trying to use QSqlSocket in my application but when I delete it (manually or not), I got an exception in QSaredData line 165 :
Code:
inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; }
I just wrote a minimal code here :
here is test.h
Code:
#include <QObject>
#include <QtNetwork/QSslSocket>
{
Q_OBJECT
public:
test();
~test();
private:
QSslSocket *socket;
};
here is test.cpp
Code:
test::test() :
{
socket = new QSslSocket(this);
}
test::~test()
{
delete socket;
// I also try this but don't work too
// socket->deleteLater();
}
Here is the main program :
Code:
int main(int argc, char *argv[])
{
test t;
}
Can you help me please ?
Thank you
Re: QSqlsocket crash when deleting
You have created the QSslSocket instance as a child of your "test" class instance (by passing "this" as an argument to the QSslSocket constructor call in line 4 of test.cpp). This gives ownership of the QSslSocket instance to the instance of "test". Because of this, the "test" class instance will delete the socket itself when it is destructed. By calling delete yourself in the test destructor, you are basically trying to delete a socket instance that has already been deleted by the QObject base class destructor.
Re: QSqlsocket crash when deleting
Hi, thank you for your answer.
Ok I understand but If I do not associate the Socket to a Q_Object, the program is still crashing when deleting it :/
Here is an example (I don't think I can do a code more small ;)):
Code:
#include "QSslSocket"
int main(int argc, char *argv[])
{
QSslSocket socket;
}
In this case, i got exactly the same error when the program close and delete the socket.
In this case, the socket is not link to anything and I don't call the detructor myself.
It's very stange :/
Re: QSqlsocket crash when deleting
Ok, I've tried to use another version of QT.
Was using Qt 5.8.0 x86 library => Crash
If using 5.7.1 x64 library => No Crash
Very strange :/
Re: QSqlsocket crash when deleting
Qt 5.8.0 with VS 2015 is working (no crash).