K
K
Kastuś2018-05-04 10:15:02
Qt
Kastuś, 2018-05-04 10:15:02

QmlRegisterType to associate with other types?

create
qmlRegisterType("myprog",1,0,"MyClass"); and everything is clear here, but let's move on
1. Can it be associated with other types in the c ++ code (signals slots)?
2. Or how to create several classes in one type and access variables in these?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
Jacob E, 2018-05-04
@Zifix

>Can I tie
him up? Who is "him"? class object? doc.qt.io/qt-5/qtqml-syntax-signals.html
>Or how to create multiple classes in one type Are we
talking about class fields? We take and create.
> and access variables in these
Q_PROPERTY

T
TriKrista, 2018-05-04
@TriKrista

You might be better off with this: qmlRegisterSingletonType

K
Kastuś, 2018-05-04
@Gytim

1. C++ wrote well :)
an example with errors (and everything is wrong XD) but something like this is needed

spoiler
oneclass.cpp
----------------
OneClass : QObject {
...
signals: void mySignal();
}
twoclass.cpp
----------------
TwoClass : QObject {
...
public slots: void mySlot(){};
}
main.cpp
----------------
#include oneclass.cpp
#include twoclass.cpp
...
qmlRegisterType("myprog.one",1,0,"MyClass");
qmlRegisterType("myprog.two",1,0,"MyClass");
QObject::connect(OneClass, SIGNAL(mySignal), TwoClass, SLOT(mySLOT));
2. Precisely classes
oneclass.cpp
----------------
OneClass : QObject {
...
Q_PROPERTY resultData(QString resultText)
public: void calculate(QString text) { resultText = text;}
}
twoclass.cpp
----------------
#include oneclass.cpp
...
TwoClass : QObject {
private:
OneClass *oneClass;
Q_INVOKABLE void biginning(QString startText) {
oneClass.calculate(startText);
}
TwoClass:TwoClass { *oneClass = new OneClass; }
}
and in qml to get the result
MyClass.result
or in the old fashioned way for now it's just to forward the references to the classes into the property?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question