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. [Solved] 'QVariant::QVariant': cannot access private member declared in class 'QVariant'

[Solved] 'QVariant::QVariant': cannot access private member declared in class 'QVariant'

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 5.5k 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.
  • N Offline
    N Offline
    nwoki
    wrote on last edited by nwoki
    #1
    // Base class
    class CommandQueue : public QThread
    {
        Q_OBJECT
    
    public:
        virtual ~CommandQueue();
    
    protected:
        void CommandQueue();
    };
    
    
    
    // Derived classes
    class ReadCommandQueue : public CommandQueue
    {
        Q_OBJECT
    
        Q_PROPERTY(bool isReadingData   READ isReadingData  NOTIFY isReadingDataChanged)
    
    
    public:
        ReadCommandQueue(QObject *parent = 0);
        ~ReadCommandQueue();
    
        bool isReadingData() const;
    
    protected:
        void run() override final;
    
    private:
        bool m_isReadingData;
    };
    
    
    class WriteCommandQueue : public CommandQueue
    {
        Q_OBJECT
    
        Q_PROPERTY(bool isWritingData   READ isWritingData  NOTIFY isWritingDataChanged)
    
    public:
        WriteCommandQueue(QObject *parent = 0);
        ~WriteCommandQueue();
    
        bool isWritingData() const;
    
    Q_SIGNALS:
        /**
         * signal used just to notify the CommandQueueCenter
         * to pull the new info written
         */
        void finishedWritingCommands();
        void isWritingDataChanged();
    
    protected:
        void run() override final;
    
    private:
        bool m_isWritingData;
    };
    
    
    
    // CommandQueueCenter has these functions
    ReadCommandQueue* CommandQueueCenter::readCommandQueue() const
    {
        return d->readCommandQueue;
    }
    
    WriteCommandQueue* CommandQueueCenter::writeCommandQueue() const
    {
        return d->writeCommandQueue;
    }
    

    I need these objects in my QML application so i expose them like i've always done as follows:

        m_centralWidget->engine()->rootContext()->setContextProperty("ApplicationData", m_core.applicationData());
        m_centralWidget->engine()->rootContext()->setContextProperty("CmdQueueCenter", m_core.commandQueueCenter());
        m_centralWidget->engine()->rootContext()->setContextProperty("MainWindow", this);
        m_centralWidget->engine()->rootContext()->setContextProperty("ReadCommandQueue", m_core.commandQueueCenter()->readCommandQueue());
    
    // This last line creates my error
        m_centralWidget->engine()->rootContext()->setContextProperty("WriteCommandQueue", m_core.commandQueueCenter()->writeCommandQueue());
    

    All was fine with the "ReadCommandQueue" but when I added the "WriteCommandQueue" i got the following error:

    'QVariant::QVariant': cannot access private member declared in class 'QVariant'
    

    Any idea why this is happening? The classes are basically identical.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Can you show the constructor of CommandQueue and WriteCommandQueue

      P.S.
      Unrelated to the problem at hand but still strange:
      void CommandQueue(); and WriteCommandQueue(QObject *parent = 0); looks like something fishy is going on with your parent-child management but I can't be sure as you did not include the implementation

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      N 1 Reply Last reply
      0
      • VRoninV VRonin

        Can you show the constructor of CommandQueue and WriteCommandQueue

        P.S.
        Unrelated to the problem at hand but still strange:
        void CommandQueue(); and WriteCommandQueue(QObject *parent = 0); looks like something fishy is going on with your parent-child management but I can't be sure as you did not include the implementation

        N Offline
        N Offline
        nwoki
        wrote on last edited by nwoki
        #3

        @VRonin said in 'QVariant::QVariant': cannot access private member declared in class 'QVariant':

        Can you show the constructor of CommandQueue and WriteCommandQueue

        CommandQueue::CommandQueue(QObject *parent)
            : QThread(parent)
            , m_connectionStatus(ConnectorStatus::Disconnected)
        {
        }
        
        
        WriteCommandQueue::WriteCommandQueue(QObject *parent)
            : CommandQueue(parent)
            , m_isWritingData(false)
        {
        }
        
        
        ReadCommandQueue::ReadCommandQueue(QObject *parent)
            : CommandQueue(parent)
            , m_isReadingData(false)
        {
        }
        

        I added the ReadCommandQueue as well as it didn't cost me anything to do a copy/paste

        P.S.
        Unrelated to the problem at hand but still strange:
        void CommandQueue(); and WriteCommandQueue(QObject *parent = 0); looks like something fishy is going on with your parent-child management but I can't be sure as you did not include the implementation

        Yeah, whilst removing implementation deatials i erroneously deleted the QObject *parent = nullptr . Sorry about that

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          Try cleaning the project and re-running qmake, looks like the Q_OBJECT wasn't spotted by moc.

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          N 1 Reply Last reply
          0
          • VRoninV VRonin

            Try cleaning the project and re-running qmake, looks like the Q_OBJECT wasn't spotted by moc.

            N Offline
            N Offline
            nwoki
            wrote on last edited by
            #5

            Already did that. Same problem. That's why I can't figure out this error. All the right pieces are in place. (Well, apparently not..)

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              The problem is that setContextProperty is calling the QVariant overload instead of the QObject one and QVariant(void*) is private. QVariant::fromValue(m_core.commandQueueCenter()->writeCommandQueue()) should solve the copilation but unsure if it's ok

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nwoki
                wrote on last edited by
                #7

                Yeah, it should be calling the QObject* overload. For now the issue has been fixed with a cast

                m_centralWidget->engine()->rootContext()->setContextProperty("WriteCommandQueue", (QObject*)m_core.commandQueueCenter()->writeCommandQueue());
                

                but does anyone know why the wrong overload is being called?

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  Does main() (or wherever you call setContextProperty from) know WriteCommandQueue is a QObject? i.e. did you include writesommandqueue.h or is it just forward declared like class WriteCommandQueue;?

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  N 1 Reply Last reply
                  2
                  • VRoninV VRonin

                    Does main() (or wherever you call setContextProperty from) know WriteCommandQueue is a QObject? i.e. did you include writesommandqueue.h or is it just forward declared like class WriteCommandQueue;?

                    N Offline
                    N Offline
                    nwoki
                    wrote on last edited by
                    #9

                    @VRonin said in 'QVariant::QVariant': cannot access private member declared in class 'QVariant':

                    Does main() (or wherever you call setContextProperty from) know WriteCommandQueue is a QObject? i.e. did you include writesommandqueue.h or is it just forward declared like class WriteCommandQueue;?

                    alt text

                    I forgot the inclusion.. Was convinced I had already done it. Thanks

                    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