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.2k 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 11 Mar 2016, 14:59 last edited by Jakob 3 Nov 2016, 15:02
    #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'?

    K 1 Reply Last reply 11 Mar 2016, 15:19
    0
    • J Jakob
      11 Mar 2016, 14:59

      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'?

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 11 Mar 2016, 15:19 last edited by kshegunov 3 Nov 2016, 21:37
      #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

      2/2

      11 Mar 2016, 15:19

      • Login

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