Qt World Summit: Register Today!

Updating a text field in QML using C++

  • I'm trying to write into this text field new messages provided by my C++ code function

     Item {
            id: recogPercent
            width: parent.width
            height: parent.height*0.07
            anchors.top: cameraRectangle.bottom
            property alias text1Text: text1.text
            Text {
                id: text1
                height: parent.height
                width: parent.width
                color: "#FFF"
                text: "0000000"
                font.pixelSize: 100

    and I tried to use this example in Qt doc, and the console log print the right message but the interface doesn't change.

    QQmlEngine engine;
    QQmlComponent component(&engine, "MyItem.qml");
    QObject *object = component.create();
    qDebug() << "Property value:" << QQmlProperty::read(object, "text1Text").toInt();
    QQmlProperty::write(object, "text1Text", 5000);
    qDebug() << "Property value:" << object->property("text1Text").toInt();
    object->setProperty("text1Text", 100);

    any idea why this happens?

    obs: I'm deploying to Android.

  • Hi! Maybe the following very similar thread helps: https://forum.qt.io/topic/74151

  • @Wieland I already tried this but I keep receiving Component not ready and my application crash.
    I used QStringLiteral in Url too but nothing changed.

  • Moderators

    @OliveiraNT Probably the component was not created and you are writing property of a null component? QQmlComponent::errors() will give you some more info.

Log in to reply