Good day! I can not solve the problem:
I develop the menu on QTQuick 5.7 There are several QML forms: main.qml, Page.qml, Options.qml ...
There is a button in main.qml:
Button { id: button1 x: 178 y: 227 text: qsTr("PressMe") onClicked: { button1.text = "Clicked" var result = testclasses.getSomeProperty() } } When you press a button, a certain testclasses function is called. getSomeProperty ()
The class with this function is defined in main.h:
class TestClass : public QObject { Q_OBJECT public: Q_INVOKABLE void getSomeProperty(); }; The method is implemented as:
void TestClass::getSomeProperty() { qDebug() << "Event is here"; QQuickView view; view.setSource(QUrl(QLatin1String("qrc:/Page1Form.ui.qml")) ); view.show(); QObject *object = view.rootObject(); QObject *txttxt = object->findChild<QObject*>("texttochange"); if (txttxt){ qDebug() << txttxt->property("text"); txttxt->setProperty("text", "текст изменен"); qDebug() << txttxt->property("text"); } } An instance of the class is created in Main:
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; QQmlContext* context = engine.rootContext(); TestClass tc; context->setContextProperty("testclasses", &tc); engine.load(QUrl(QLatin1String("qrc:/main.qml"))); app.exec(); } Made by examples from the Internet. As a result, when you press an infinite number of times on the button, the log is displayed in this way
Debug \ debug \ Memograph.exe ... QML debugging is enabled. Only use this in a safe environment. Event is here QVariant (QString, "Home page") QVariant (QString, "text changed") Event is here QVariant (QString, "Home page") QVariant (QString, "text changed") Event is here QVariant (QString, " Start Page ") QVariant (QString," Text Changed ")
That is, our text seems to be changing, but in fact nothing changes. Tell me how to correctly change the attributes of qml forms from C ++ code. I work with the PLO very recently, everything is hard, but it must be done.
