P
P
Pavel K2016-03-19 20:03:52
Qt
Pavel K, 2016-03-19 20:03:52

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,        
    };
};

Another class is inherited from it, for example
class AppCore : public QObject, public CommunicationEnums
{
    Q_OBJECT
    Q_ENUMS(EButtons)
    ....... 
public:      
   Q_INVOKABLE void processButton(EButtons button);
   .......

I register it
qmlRegisterUncreatableType<AppCore>("AppCore", 2, 0, "AppCore", "Only enums");

and pass it to QML
If I write in QML:
console.log(AppCore.BTN_LEFT)
as expected, it displays 2
But if I try to call the function , it
appCore.processButton(AppCore.BTN_LEFT);
displays
Error: Unknown method parameter type: EButtons

Moreover, if enum { ... } transferred to AppCore, then the function call is normal O_o
Em, what to do and who is to blame?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abukirev, 2016-04-19
@abukirev

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 question

Ask a Question

731 491 924 answers to any question