Search code examples
c++qtqt4qt-creator

Singleton class issue in Qt


i created a singleton class and trying to access that class in other class but getting error "cannot access private member"

Setupconfig is my singleton class and i am trying to access this class in other class which have QMainWindow

And here is the error message:

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

Setupconfig.h
static Setupconfig *buiderObj()
{
    static Setupconfig *_setupObj= new Setupconfig();
    return _setupObj;
}

private:
Setupconfig();

//////////////////////////////////////
EasyBudget.h
class EasyBudget : public QMainWindow, public Ui::EasyBudgetClass, public Setupconfig
{
Q_OBJECT
public:
Setupconfig *setupObj;
}

//////////////////////////////////////
EasyBudget.cpp
EasyBudget::EasyBudget(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent,Qt::FramelessWindowHint)
 {
 setupObj=Setupconfig::buiderObj();
 }

Solution

  • Why are you deriving "EasyBudget" from the singleton class "SetupConfig"?

    Remove that part to resolve your problem.

    EasyBudget.h
    class EasyBudget : public QMainWindow, public Ui::EasyBudgetClass
    {......