Results 1 to 5 of 5

Thread: Crash on deletion of QScriptEngine object

  1. #1
    Join Date
    Mar 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Crash on deletion of QScriptEngine object

    Hi,

    on start of my app I create a new QScriptEngine object, use it for a lot of stuff and destroy it before quitting the app. Unfortunately the app crashes when coming to the line with the delete.
    I do so many things with the object during its lifetime, and I don't have any clue, what could be the reason for this. That's also why I can't post any source code here... Any ideas anybody? Thanks.

    Cheers,
    Tim

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Crash on deletion of QScriptEngine object

    Please post the stack backtrace from the debugger.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Crash on deletion of QScriptEngine object

    Qt Code:
    1. 0 ~QObject qobject.cpp 954 0x6a20d95b
    2. 1 ~MainWindow mainwindow.cpp 166 0x00402d25
    3. 2 ~QObjectDelegate qscriptqobject.cpp 1156 0x0a5d2f70
    4. 3 ~Data qscriptobject.cpp 42 0x0a5cadea
    5. 4 ~QScriptObject qscriptobject.cpp 52 0x0a5caf11
    6. 5 QTJSC::Heap::sweep<(QTJSC::HeapType)0> Collector.cpp 1156 0x0a614e8f
    7. 6 QTJSC::Heap::destroy Collector.cpp 199 0x0a5530f7
    8. 7 ~QScriptEnginePrivate qscriptengine.cpp 838 0x0a5b6277
    9. 8 QScopedPointerDeleter<QObjectData>::cleanup qscopedpointer.h 62 0x6a267efe
    10. 9 ~QScopedPointer qscopedpointer.h 100 0x6a25e701
    11. 10 ~QObject qobject.cpp 992 0x6a20cfd0
    12. 11 ~QScriptEngine qscriptengine.cpp 1488 0x0a5b8d94
    13. 12 ~MainWindow mainwindow.cpp 166 0x00402a75
    14. 13 qMain main.cpp 9 0x0040140d
    15. 14 WinMain@16 qtmain_win.cpp 131 0x0046da72
    16. 15 main 0 0x0046d798
    To copy to clipboard, switch view to plain text mode 

    Looking at this again I had an idea...
    As you can see, the destructor of MainWindow appears twice in the stack backtrace. Then I realized that I'm wrapping the MainWindow object in a ScriptValue:
    Qt Code:
    1. QScriptValue scriptMainWnd = engine->newQObject(mainWnd, QScriptEngine::ScriptOwnership);
    To copy to clipboard, switch view to plain text mode 
    Does the destructor of QScriptEngine also delete all the objects connected to its QScriptValues? Then of course this would make perfect sense, since the destruction of the QScriptEngine would yield the destruction of the MainWindow. But that's just a wild guess...

    Cheers,
    Tim

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Crash on deletion of QScriptEngine object

    Quote Originally Posted by The_Fallen View Post
    Does the destructor of QScriptEngine also delete all the objects connected to its QScriptValues?
    If you add them with script ownership then yes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Crash on deletion of QScriptEngine object

    Yes, I'm stupid... If I change the ownership to QtOwnership, everything works fine. Thanks a lot! :-)

Similar Threads

  1. deletion problem with QGraphicsScene
    By spawn9997 in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2010, 20:49
  2. QScriptEngine
    By coderbob in forum Qt Programming
    Replies: 10
    Last Post: 25th January 2010, 16:12
  3. QScriptEngine in Qt 4.6.0
    By Fastman in forum Qt Programming
    Replies: 0
    Last Post: 25th December 2009, 21:00
  4. QTextCursor and QScriptEngine
    By roxton in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2008, 19:47

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.