I'm having a hard time figuring out how the classes are defined in Qt.
I'll take the QT5 JSON API as an example:
QJsonValue is a class representing any JSON value. It can be converted to a QJsonObject, QJsonArray, or to the standard types like QString, int, etc.
Now, the QJsonValue header looks like this (I stripped non-relevant parts, the complete file is here):
#include <QtCore/qglobal.h>
#include <QtCore/qstring.h>
class QDebug;
class QVariant;
class QJsonArray;
class QJsonObject; // class is pre-declared
class Q_CORE_EXPORT QJsonValue
{
QJsonValue(const QJsonObject &o);
QJsonObject toObject() const; // how does this work without
// any info on QJsonObject class structure??
// ...
}
What bothers me is that QJsonObject
is pre-declared as an existing class, but I figure that without any information on the inners of the class, the toObject()
method won't compile (although it doest, including only <QJsonValue>
doesn't fail).
I'm not so sure about the const reference, since it might not need the full class description, but just the address.
Problem is, there is never an include of QJsonObject.h anywhere in the file.
Is this magic or what?