Hello everyone, this will be my very first thread. I am currently learning qt from tutorials and books. At some point, I implemented this class with Private
Implementation covered with QScopedPointer.
***1) Here is my MasterController class with a forward declaration of class "Implementation" with QScoped Pointer guards it.
class CMLIB_EXPORT MasterController
: public QObject{
Q_OBJECT
public:
explicit MasterController
(QObject* parent
= nullptr
);
~MasterController();
cm::controllers::NavigationController* ui_navigationController();
signals:
private:
class Implemantation;
QScopedPointer<Implemantation> implementation;
};
class CMLIB_EXPORT MasterController : public QObject
{
Q_OBJECT
public:
explicit MasterController(QObject* parent = nullptr);
~MasterController();
cm::controllers::NavigationController* ui_navigationController();
signals:
private:
class Implemantation;
QScopedPointer<Implemantation> implementation;
};
To copy to clipboard, switch view to plain text mode
*** 2) Here is also my cpp file for MasterController class. Here we see previously declared Implemation class as well as constructor, deconstructor of Master Class.
class MasterController::Implemantation
{
public:
Implemantation(MasterController* _masterController) : masterController(_masterController)
{
navigationController = new NavigationController(masterController);
}
~Implemantation()
{
}
MasterController* masterController;
NavigationController* navigationController;
QString welcomeMessage
= "This is MasterController to Major Tom";
};
{
//implementation is a scoped pointer
implementation.reset(new Implemantation(this));
}
MasterController::~MasterController()
{
}
NavigationController* MasterController::ui_navigationController()
{
return implementation->navigationController;
}
class MasterController::Implemantation
{
public:
Implemantation(MasterController* _masterController) : masterController(_masterController)
{
navigationController = new NavigationController(masterController);
}
~Implemantation()
{
}
MasterController* masterController;
NavigationController* navigationController;
QString welcomeMessage = "This is MasterController to Major Tom";
};
MasterController::MasterController(QObject* parent) : QObject(parent)
{
//implementation is a scoped pointer
implementation.reset(new Implemantation(this));
}
MasterController::~MasterController()
{
}
NavigationController* MasterController::ui_navigationController()
{
return implementation->navigationController;
}
To copy to clipboard, switch view to plain text mode
*** 3) Here is my Question: My private implemented Class (Implementation) has 3 members :
a- MasterController class that it lives on
b- Someother Navigation Class
c- A String
If my MasterController class comes to the end of scope , everythis is fine, all objects are deleted. From curiosity, i deleted Destructor from MasterController and i got following compile errors:
C:\Qt\5.14.2\msvc2017_64\include\QtCore\qscopedpoi nter.h:57: error: C2027: use of undefined type 'cm::controllers::MasterController::Implemantation '
c:\qtprojects\cm-learningqt\customermanager\cm-lib\source\controllers\mastercontroller.h:34: see declaration of 'cm::controllers::MasterController::Implemantation '
C:\Qt\5.14.2\msvc2017_64\include\QtCore\qscopedpoi nter.h:53: while compiling class template member function 'void QScopedPointerDeleter<T>::cleanup(T *)'
with
[
T=cm::controllers::MasterController::Implemantatio n
]
I would be pleased if someone explains what the problem is and why destructor is important here.
Thanks in advance
Bookmarks