|
Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
|
qmlCppOwned() – protect Q_INVOKABLE QObject returns from QML's GC. More...
#include <QQmlEngine>Go to the source code of this file.
Functions | |
| template<typename T> | |
| static T * | qmlCppOwned (T *obj) |
| Hand QML CppOwnership of a C++-owned QObject returned from a Q_INVOKABLE. | |
qmlCppOwned() – protect Q_INVOKABLE QObject returns from QML's GC.
Definition in file qmlownership.h.
|
inlinestatic |
Hand QML CppOwnership of a C++-owned QObject returned from a Q_INVOKABLE.
Q_INVOKABLE (and slot) returns of a parentless QObject default to JavaScriptOwnership, so QML's garbage collector frees them once the QML-side reference is dropped (e.g. a details editor closes). That leaves a dangling pointer in the owning C++ container -> use-after-free crash on the next access. These savefile objects are owned by their container in C++ for its lifetime, so QML must never delete them. (Q_PROPERTY returns do NOT need this – QML already assumes CppOwnership for those.)
Wrap any "...At()"-style Q_INVOKABLE return: return qmlCppOwned(vec.at(ind));
| obj | The C++-owned object being returned to QML (may be nullptr). |
obj unchanged, now pinned to C++ ownership. Definition at line 43 of file qmlownership.h.
Referenced by Storage::boxAt(), AreaMap::connAt(), PokemonStorageModel::getBoxMon(), PokemonStorageModel::getPartyMon(), AreaPokemon::grassMonsAt(), ItemStorageBox::itemAt(), PokemonBox::movesAt(), PlayerPokemon::partyAt(), HoFRecord::pokemonAt(), PokemonStorageBox::pokemonAt(), HallOfFame::recordAt(), AreaSign::signAt(), AreaSprites::spriteAt(), AreaWarps::warpAt(), and AreaPokemon::waterMonsAt().