Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Updating a text field in QML using C++
Forum Update on Monday, May 27th 2025

Updating a text field in QML using C++

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • OliveiraNTO Offline
    OliveiraNTO Offline
    OliveiraNT
    wrote on last edited by A Former User
    #1

    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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

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

      OliveiraNTO 1 Reply Last reply
      1
      • ? A Former User

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

        OliveiraNTO Offline
        OliveiraNTO Offline
        OliveiraNT
        wrote on last edited by OliveiraNT
        #3

        @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.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

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

          157

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved