Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unexpected crash upon application exit
QtWS25 Last Chance

Unexpected crash upon application exit

Scheduled Pinned Locked Moved Unsolved General and Desktop
qobjectqmetaobjectqt5qscopedpointer
2 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jakob
    wrote on last edited by Jakob
    #1

    In an earlier question I asked about resource management with Qt, and in particular about the RAII principle (see: http://forum.qt.io/topic/61842/how-can-i-ensure-proper-resource-management-raii-when-using-qt-plugins).

    In one of the answers it was mentioned that in theory with Qt it is not necessary to think about this too much, because Qt internally keeps track of the lifetime of QObjects.

    I created a very small code snippet that seems to indicate the opposite: http://paste.ubuntu.com/15347864/.
    Running this snippet causes a nullptr-exception in qscopedpointer.h on line 112 (the line number is for Qt 5.6.0 beta, on hash 38e602d0f). Allthough I'm referring to Qt 5.6, I noticed the same problem already in Qt 5.4.

    Did I stumble on a subtle, yet important bug, or did I something 'illegal'?

    kshegunovK 1 Reply Last reply
    0
    • J Jakob

      In an earlier question I asked about resource management with Qt, and in particular about the RAII principle (see: http://forum.qt.io/topic/61842/how-can-i-ensure-proper-resource-management-raii-when-using-qt-plugins).

      In one of the answers it was mentioned that in theory with Qt it is not necessary to think about this too much, because Qt internally keeps track of the lifetime of QObjects.

      I created a very small code snippet that seems to indicate the opposite: http://paste.ubuntu.com/15347864/.
      Running this snippet causes a nullptr-exception in qscopedpointer.h on line 112 (the line number is for Qt 5.6.0 beta, on hash 38e602d0f). Allthough I'm referring to Qt 5.6, I noticed the same problem already in Qt 5.4.

      Did I stumble on a subtle, yet important bug, or did I something 'illegal'?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @Jakob
      Switch the order of the construction of objects. When the parent's destructor runs it'll try to free its children, but since you've created it after the child (hence its destructor will be called first), it will try to delete a stack object.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved