Usings enums as the return type of a function, does not work in qml
-
Hey, I am trying to return an enum from my C++ code, my enum is defined in a namespace, and looks like this:
// book_operation_status.hpp namespace application { Q_NAMESPACE enum class BookOperationStatus { Success, ... }; Q_ENUM_NS(BookOperationStatus) } // namespace application
I am trying to export it to qml, using (in main.cpp)
qmlRegisterUncreatableMetaObject(application::staticMetaObject, "Librum.enums", 1, 0, "BookOperationStatus", "This enum is uncreatable")
When trying to import and use it in qml, it works just fine, I can console.log() any enum value.
But when trying to return it from a c++ function, called from QML, I get the error:qml:134: Error: Unknown method return type: application::BookOperationStatus
Does anyone have an idea why this happens?
Thanks in advance.Also: my QML code, my enum and the c++ function which returns the enum, are all in different binaries (shared libraries). Maybe this is important here.
-
You probably need to also register "application::BookOperationStatus" as meta object.
Also, remember that QML does not quite understand enums, if you want to store it in QML you need to use
int
. -
You probably need to also register "application::BookOperationStatus" as meta object.
Also, remember that QML does not quite understand enums, if you want to store it in QML you need to use
int
.@sierdzio How exactly would I register the enum as a meta object?
-
I meant
Q_DECLARE_METATYPE(application::BookOperationStatus)
but it probably does not apply in this case.