qmlRegisterType of class with no default constructor
Solved
QML and Qt Quick
-
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? -
From Overview - QML and C++ Integration :
I guess what you need is one of the two at the bottom.
-
@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.