[Solved] 'QVariant::QVariant': cannot access private member declared in class 'QVariant'
-
// 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.
-
Can you show the constructor of
CommandQueueandWriteCommandQueueP.S.
Unrelated to the problem at hand but still strange:
void CommandQueue();andWriteCommandQueue(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 -
Can you show the constructor of
CommandQueueandWriteCommandQueueP.S.
Unrelated to the problem at hand but still strange:
void CommandQueue();andWriteCommandQueue(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@VRonin said in 'QVariant::QVariant': cannot access private member declared in class 'QVariant':
Can you show the constructor of
CommandQueueandWriteCommandQueueCommandQueue::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();andWriteCommandQueue(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 implementationYeah, whilst removing implementation deatials i erroneously deleted the
QObject *parent = nullptr. Sorry about that -
Try cleaning the project and re-running qmake, looks like the Q_OBJECT wasn't spotted by moc.
-
-
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?
-
Does
main()(or wherever you callsetContextPropertyfrom) knowWriteCommandQueueis a QObject? i.e. did you include writesommandqueue.h or is it just forward declared likeclass WriteCommandQueue;?@VRonin said in 'QVariant::QVariant': cannot access private member declared in class 'QVariant':
Does
main()(or wherever you callsetContextPropertyfrom) knowWriteCommandQueueis a QObject? i.e. did you include writesommandqueue.h or is it just forward declared likeclass WriteCommandQueue;?
I forgot the inclusion.. Was convinced I had already done it. Thanks