Answer the question
In order to leave comments, you need to log in
Some misunderstandings with Q_ENUMS and Q_INVOKABLE when inheriting, why?
Greetings
Let's say there is a class with enums, for example
class CommunicationEnums {
public:
CommunicationEnums() {}
enum EButtons {
BTN_LEFT = 2,
BTN_RIGHT = 4,
};
};
class AppCore : public QObject, public CommunicationEnums
{
Q_OBJECT
Q_ENUMS(EButtons)
.......
public:
Q_INVOKABLE void processButton(EButtons button);
.......
qmlRegisterUncreatableType<AppCore>("AppCore", 2, 0, "AppCore", "Only enums");
console.log(AppCore.BTN_LEFT)
appCore.processButton(AppCore.BTN_LEFT);
Error: Unknown method parameter type: EButtons
enum { ... }
transferred to AppCore, then the function call is normal O_o Answer the question
In order to leave comments, you need to log in
1. Try registering the enum itself like this:
Q_DECLARE_METATYPE(CommunicationEnums::EButtons)
and
qmlRegisterUncreatableType("EButtons", 1, 0, "EButtons", "Error class uncreatable");
2. As far as I remember, there was such a problem in 5.2, they even found a bug with a description in the Qt bugtracker. The bottom line is that the meta-object system did not register enumerations normally and they had to be duplicated in each class that was accessed from QML.
What version of Qt do you have?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question