Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error -: 'QObject::QObject' : cannot access private member declared in class 'QObject'

Tags:

c++

qt

I am trying to return a class that is derived from QObject and I am getting the following error

Error : 'QObject::QObject' : cannot access private member declared in class 'QObject'   

This situation resembles my scenario

Header File : B.h

class B : public QObject
{
        Q_OBJECT
        private:
            ...
        public:
            B(QObject* parent = 0);
            ...
}

CPP File : B.cpp

B:B(QObject *parent)
{
//Empty Constructor
}

Header File : A.h

class A
{
private:
     B myClassB;
public :
     B ReturnClassB();
}

CPP File : C.cpp

B A::ReturnClassB()
{
   return myClassB; //This is where the error occurs
}

Any suggestions on what might be going wrong ? Is it a copy constructor issue ?

like image 622
Rajeshwar Avatar asked Apr 17 '26 14:04

Rajeshwar


1 Answers

The QObject class has a private copy constructor. As such you can not copy instances of classes that derive from QObject. See also this page on the identity vs. value discussion regarding QObject.

If you want to be able to copy instances of B, either don't inherit from QObject or provide some means of cloning B (taking care to ensure that memory is managed appropriately).

like image 199
RA. Avatar answered Apr 20 '26 02:04

RA.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!