qmlRegisterType of class with no default constructor
-
wrote on 1 Jul 2019, 08:13 last edited by
Hello. I'm working on a QML application. I try to expose my Class to QML, but at compilation i get errors linked to qmlRegisterType use.
Here is my class constructor:explicit PowerSupplyControl(CanOpenNodeId nodeId,QObject *parent = nullptr);
and the way i register it in my main:
qmlRegisterType<PowerSupplyControl>("com.device",1,0,"CanDevice");
My class inherit another custom one.
Anyone can help? -
-
Hello. I'm working on a QML application. I try to expose my Class to QML, but at compilation i get errors linked to qmlRegisterType use.
Here is my class constructor:explicit PowerSupplyControl(CanOpenNodeId nodeId,QObject *parent = nullptr);
and the way i register it in my main:
qmlRegisterType<PowerSupplyControl>("com.device",1,0,"CanDevice");
My class inherit another custom one.
Anyone can help?wrote on 1 Jul 2019, 08:44 last edited by@Babs As far as I known, to register a type with
qmlRegisterType()
, the class must:- be a subclass from QObject
- have a default constructor, to enable QML engine to create an instance
If you only want QML to be aware from class, for example to have access to enumeration, you can use
qmlRegisterUncreatableType()
.Take a look at https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html fro more details.
-
@Babs As far as I known, to register a type with
qmlRegisterType()
, the class must:- be a subclass from QObject
- have a default constructor, to enable QML engine to create an instance
If you only want QML to be aware from class, for example to have access to enumeration, you can use
qmlRegisterUncreatableType()
.Take a look at https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html fro more details.
wrote on 1 Jul 2019, 10:26 last edited by@KroMignon thank you. I did it successfully.
1/4