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. Can someone explain (QThread and QThreadPrivate)
Qt 6.11 is out! See what's new in the release blog

Can someone explain (QThread and QThreadPrivate)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RavensAngel
    wrote on last edited by
    #1

    I was monitoring my app for leaks etc ... and a leak indication came up at QThread. So i looked to the constructor etc ... and found this piece of code in it.

    QThread::QThread(QObject parent)
    : QObject(
    (new QThreadPrivate), parent)

    Looking at QObject:

    QObject::QObject(QObjectPrivate &dd, QObject *parent)
    : d_ptr(&dd)

    at QObject the d_ptr never gets a cleanup.

    But at QThread the new QThreadPrivate is never cleaned up either...

    So, as this is a core class and alot of people are using it. It can't really be a leak (i assume) as this would be detected already a long time ago... but i can't really find anything related to this subject...
    So is there someone willing to explain? Or give an opinion on this matter?

    Thx

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      The d_ptr is not stored as a raw pointer, but as a QScopedPointer in QObject. QScopedPointer will take care of the deletion when it goes out of scope, that is, when the QObject is deleted.

      See the qobject.h file, around line 450 (Qt 5.3.1, may be different for other Qt versions).

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RavensAngel
        wrote on last edited by
        #3

        Oh, i overlooked that!

        Thank you for that answer!

        1 Reply Last reply
        0

        • Login

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