This can be called a design pattern used to increase the readability of header files from this class, hiding everything that the class user should not know about.
So, instead of defining a header file from a given class header, which consists of public and private data, Qt often decides to put private data from the class into a separate class. This separate class is then used as a private member from the source class.
For example, instead of:
class MyClass { public: MyClass(); ~MyClass(); QVariant getValue1(); QVariant getValue2(); QVariant getValue3(); private: QVariant m_Value1; QVariant m_Value2; QVariant m_Value3; };
We could have the following
class MyClass { public: MyClass(); ~MyClass(); QVariant getValue1(); QVariant getValue2(); QVariant getValue3(); private: friend class MyClassPrivate; };
where MyClassPrivate is defined as follows
class MyClassPrivate { public: MyClassPrivate (); ~MyClassPrivate (); QVariant m_Value1; QVariant m_Value2; QVariant m_Value3; };
In other words, all private members of a class are therefore "exported" to the public definition of a private class.
For me, this is a way to make the class header file that the user will work with more readable. This is especially true when it comes to classes requiring a large number of private members.
source share