Answer the question
In order to leave comments, you need to log in
How to create a QML type?
It is necessary to create models of a group of physical bodies with the ability to edit their parameters without recompilation. I decided to use QML for this business - a convenient syntax, you can declare functions for a specific calculation of parameters. Everything is cool, but I would like to move away from Quick as much as possible.
Created 2 classes:
class Model : public QObject
{
Q_OBJECT
public:
explicit Model(QObject *parent = Q_NULLPTR);
}
class Anode : public QObject
{
Q_OBJECT
public:
explicit Anode(QObject *parent = Q_NULLPTR);
}
int main(int argc, char *argv[])
{
qmlRegisterType<Model>("Model", 1, 0, "Model");
qmlRegisterType<Anode>("Model", 1, 0, "Anode");
// ...
}
import Model 1.0
Model {
Anode {
}
}
QQmlEngine engine;
QQmlComponent component(&engine);
component.loadUrl(QUrl("types/type1.qml"));
QObject *myObject = component.create();
QQmlApplicationEngine engine;
engine.load(QUrl("types/type1.qml"));
import Model 1.0
Model {
anode: Anode {
}
}
Answer the question
In order to leave comments, you need to log in
Ok, I figured this out:
Model {
anode: Anode {
}
}
QML_DECLARE_TYPE(Model)
QML_DECLARE_TYPE(Anode)
Model {
Anode {
}
}
class Model : public QObject
{
Q_OBJECT
Q_PROPERTY(Anode* anode READ anode WRITE setAnode NOTIFY anodeChanged)
Q_PROPERTY(QObject* item WRITE addItem)
Q_CLASSINFO("DefaultProperty", "item")
public:
explicit Model(QObject *parent = Q_NULLPTR);
public slots:
void addItem(QObject* item);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question