+ Reply to Thread
Results 1 to 5 of 5

Thread: QSqlsocket crash when deleting

  1. #1
    Join Date
    Apr 2017
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default 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 :
    Qt Code:
    1. inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; }
    To copy to clipboard, switch view to plain text mode 

    I just wrote a minimal code here :

    here is test.h
    Qt Code:
    1. #include <QObject>
    2. #include <QtNetwork/QSslSocket>
    3.  
    4. class test : public QObject
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. test();
    10. ~test();
    11.  
    12. private:
    13. QSslSocket *socket;
    14. };
    To copy to clipboard, switch view to plain text mode 

    here is test.cpp
    Qt Code:
    1. test::test() :
    2. QObject(NULL)
    3. {
    4. socket = new QSslSocket(this);
    5. }
    6.  
    7. test::~test()
    8. {
    9. delete socket;
    10. // I also try this but don't work too
    11. // socket->deleteLater();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Here is the main program :
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication application(argc, argv);
    4.  
    5. test t;
    6. }
    To copy to clipboard, switch view to plain text mode 

    Can you help me please ?

    Thank you

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,216
    Thanks
    194
    Thanked 505 Times in 495 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default 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.
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2017
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default 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 ):

    Qt Code:
    1. #include "QSslSocket"
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5.  
    6. QSslSocket socket;
    7. }
    To copy to clipboard, switch view to plain text mode 

    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 :/

  4. #4
    Join Date
    Apr 2017
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default 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 :/

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,317
    Thanked 243 Times in 239 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlsocket crash when deleting

    Qt 5.8.0 with VS 2015 is working (no crash).

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 3rd November 2015, 17:58
  2. Replies: 2
    Last Post: 16th October 2011, 23:25
  3. Crash gracefully? No crash!
    By lni in forum Qt Programming
    Replies: 0
    Last Post: 7th July 2010, 03:59
  4. Deleting Class causes app crash
    By been_1990 in forum Qt Programming
    Replies: 8
    Last Post: 29th January 2010, 17:52
  5. Deleting a Folder
    By GTBuilder in forum Newbie
    Replies: 9
    Last Post: 29th September 2009, 06:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts