[C++] Playing with references and types can be hazardous

Well, working on my own Game Engine this week-end, I lost like 5 hours of my life debugging it … and finally, I found that I played with references and types without paying enough attention at it.

inline static bool loadDouble(const QJsonObject& qJsonObject, const char* valueName, quint32& out_int) {
    double d;
    bool res = loadDouble(qJsonObject, valueName, d);
    out_int = d;
    return res;
}

This resulted in writing the end of the d double outside of the out_int quint32.
Simply casting the double solved the overflow.

inline static bool loadDouble(const QJsonObject& qJsonObject, const char* valueName, quint32& out_int) {
    double d;
    bool res = loadDouble(qJsonObject, valueName, d);
    out_int = (quint32)d;
    return res;
}

[Qt] Using QResources

Adding a QResource to your project :

  •  Add new > Qt > Qt Resource file.

Make sure every single qrc file has been added to RESOURCES in your .pro file.

Then load every resource files added to your project in you main :

Q_INIT_RESOURCE(res);

Don’t forget that the path to a QResource has the following form “:/prefix/pathToYourResource” and that you can use aliases in your QResource file.