Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.9.6, 5.12.0
-
None
Description
The Issue In Brief
Given a QObject derived type defined within a namespace...
namespace MyNamespace { class MyClass : public QObject { ... }; }
If a Q_INVOKABLE function returns a pointer to MyClass to the QmlEngine...
namespace MyNamespace { class Controller : public QObject { ... Q_INVOKABLE MyClass* getMyClass(); } };
The QmlEngine does not recognize the return type. Console output:
"Error: Unknown method return type: MyClass*"
This occurs even though both MyClass and Controller are properly registered types:
qmlRegisterSingletonType<MyNamespace::Controller>(uri, 1, 0, "Controller", &MyNamespace::Controller::qmlInstance); qmlRegisterUncreatableType<MyNamespace::MyClass>(uri, 1, 0, "MyClass", "Get instances via Controller API");
Workaround
I discovered that if I use a fully qualified type name as the return type for the Q_INVOKABLE function, then the issue is avoided.
namespace MyNamespace { class Controller : public QObject { ... Q_INVOKABLE MyNamespace::MyClass* getMyClass(); } };
I have uploaded a minimal sample plugin and demo app that demonstrates this issue and the workaround.
Attachments
Issue Links
- resulted in
-
QTBUG-73804 Document how to use Qt Metatype system with types in C++ namespaces
- Reported