How do I return "null" from C++ to QML?
Unsolved
QML and Qt Quick
-
@eddy Not exactly the same thing. That link talks about C++ producing a nullptr value when the expected type is pointer-to-something-derived-from-QObject, but I'm trying to return a QVariant, not a pointer to a QVariant.
Ultimately, I want my Q_INVOKABLE member function to be able to return a QByteArray, a QString, or something that converts to null, so I can write in QML:
var v = objId.memFunc() if (v === null) processNothing() else if (typeof(v) === "string") processMessage(v) else processData(new Uint8Array(v))
It looks to me like QVariant is the correct type for memFunc() to return, but for all the conversions described by the docs, "null" seems to have been left out. Or am I wrong, and I'm supposed to be returning a pointer to a "new QVariant" pointer for the QByteArray and QString cases, and nullptr for the null case?