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. Porting Qt 4.8 to 5.9 - does QSharedPointer need QObject data now?
Forum Updated to NodeBB v4.3 + New Features

Porting Qt 4.8 to 5.9 - does QSharedPointer need QObject data now?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 712 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.
  • G Offline
    G Offline
    Graham Bartlett
    wrote on last edited by Graham Bartlett
    #1

    I'm porting an older Qt application from 4.8.3 to 5.9.1. The code uses QSharedPointer for singleton chunks of functionality which are shared between various places, so that they will clean up after themselves when things shut down. Inside the QSharedPointer::internalConstruct() function though I'm getting an error that "'QObject' is an inaccessible base of 'Elektron::MPS9000::DiagnosticsProtocolHandler'" (the class I'm creating a pointer to). This error did not occur on 4.8.3.

    Now it's right - that class does not derive from QObject. (To be more precise, the concrete class does derive from QObject, but the abstract base class used for the QSharedPointer typename doesn't need to know that.) But my understanding of QSharedPointer is that the data it's pointing to should be able to be any type - I've found examples online for "QSharedPointer<int>", for example.

    The line in question in QSharedPointer::internalConstruct() is

    d->setQObjectShared(ptr, true);

    Based on that, it looks to me like QSharedPointer in Qt 5.9.1 is now requiring the data it points to to derive from QObject. So "QSharedPointer<int>" or whatever my code does are no longer possible on Qt5.

    Can anyone confirm or deny this?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      This is working perfectly fine:

      class Foo
      {
      public:
          Foo() = default;
          int myParam = 0;
      };
      
      void test()
      {
          QSharedPointer<Foo> f1(new Foo);
          QSharedPointer<Foo> f2 = QSharedPointer<Foo>::create();
      }
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • G Offline
        G Offline
        Graham Bartlett
        wrote on last edited by
        #3

        Thanks Christian. Not sure what's going on then, for this code to break the internals of QSharedPointer! Ah well, more work needed to figure this out then. At least if it's not a Qt issue, that's one less thing to worry about.

        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