Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
6.3
Description
Let's say I want return `std::optional<int>` or `std::optional<QColor>` or `std::optional<QString>` from C++ to QML via `Q_INVOKABLE` function.
I see only one option to do it now: usage of `QVariant()` and `QVariant(T)`.
In other words it would be dynamic typing: type `T` or invalid type.
I can define new types like `OptionalT`:
struct OptionalT { Q_GADGET bool isValid; T data; Q_PROPERTY(...) };
because of `Q_GADGET` not supported as return type for `Q_INVOKABLE` (https://bugreports.qt.io/browse/QTBUG-79330).
The propblem that on QML type become `var`, and qmllint can not reports any warning for code like this:
const depTime = obj.getDepartureTime() if (depTime) { return depTime.toLocalString(Qt.locale(), "hh:mm\nt") // <-- here error, no "e" on Locale } else return qsTr("Departure time")
It would be nice if there is option to annotate nullable types on C++/QML border.