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. Inheriting from QObjectPrivate
QtWS25 Last Chance

Inheriting from QObjectPrivate

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 7.4k 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.
  • R Offline
    R Offline
    rcari
    wrote on last edited by
    #1

    Hi all!
    I am creating a library with a large class hierarchy based on QObject and all its savvy features. However, I'm worried about the overhead of dynamic memory allocation for the private (d_ptr/pimpl) class. I would rather have my own Class/ClassPrivate that would respectively inherit QObject/QObjectPrivate and that could use custom allocators, so that I can tightly manage dynamic objects allocations. I could also provide some level of ABI compatibility for my library using this d_ptr/pimpl for myself alongside Qt.

    I know there is no guarantee about API and ABI compatibility of those private internal classes, but I don't really care since my only plan is to inherit QObjectPrivate and not use any of its API, apart from its default constructor. I do not care about rebuilding the library with new versions of Qt.

    Does anyone see a good reason not to attempt this? Thanks in advance!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      In Qt5, you can include private headers with QT += core-private added to your .pro file.

      I'm not sure why you are so concerned about it. All Qt uses QObjects intensively, and it works quite well :) IIRC, you can create your own PIMPL implementations with Q_Q etc. macros without access to QObjectPrivate.

      (Z(:^

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Peter K
        wrote on last edited by
        #3

        Doesn't inheriting from anything in the private parts of the library create the possibility of breaking your binary compatibility with any future version of Qt?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Headers are private for a reason. If you choose to use them, you are doing it on your responsibility. There is no promise of any compatibility for private APIs, even between patch releases. Of course, in real life, most of the code will stay the same for long periods of time.

          There is nothing inherently wrong about it, you just need to recompile your project every time you update the libraries, and be very careful to use right version with your application, including user machines.

          (Z(:^

          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