• 3406阅读
  • 4回复

[讨论]c++ 更新qml 的text  text 没变化 [复制链接]

上一主题 下一主题
离线zzxap
 

只看楼主 倒序阅读 楼主  发表于: 2017-04-13

QQmlEngine enginee;
          QQmlComponent component(&enginee, "qrc:/MainForm.ui.qml");
         QQuickItem *object = qobject_cast<QQuickItem*>(component.create());
          QObject * rect = object->findChild<QObject *>("label_speed");

         if(rect)
         {

                qDebug() <<  "find rect";
          if(rect->setProperty("text", "180"))
          {
               qDebug() <<  "set success";
qDebug() << "Text of 'speed' " << rect->property("text");
          }
          else
          {
              qDebug() <<  "set fail";
          }
     }else
         {

               qDebug() <<  "not find rect";
         }

打印日志,是set success 并且取出来的text是180 .但是UI上显示的还是旧值。。。。什么原因?
本帖提到的人: @梅克斯
离线never_forget

只看该作者 1楼 发表于: 2017-04-14
QML 属性绑定有些是不会动态变化的,给 text 一个onTextChanged 信号处理函数,然后更新文本试试看。
离线cycloveu

只看该作者 2楼 发表于: 2017-04-14
设计就不应该这么用
大道至简 悟在天成
离线zzxap

只看该作者 3楼 发表于: 2017-04-17
  Text {
         id:label_speed2;z:5;
          objectName: "label_speed2";

         x: 50;   y:160;  width: 200; height: 300;
       text: "1000";
         horizontalAlignment:TextInput.AlignHCenter
        font.pixelSize: 160
        onTextChanged :root.textChanged(label_speed_text2)
         renderType: Text.NativeRendering
       // font.italic: true
        color: "white"
    }

怎么绑定,text还是没有刷新。。
离线jockeyliao

只看该作者 4楼 发表于: 2017-06-08
QQmlEngine enginee;
          QQmlComponent component(&enginee, "qrc:/MainForm.ui.qml");
         QObject *object = component.create();
          QObject * rect = object->findChild<QObject *>("label_speed");

         if(rect)
         {

                qDebug() <<  "find rect";
          if(rect->setProperty("text", "180"))
          {
               qDebug() <<  "set success";
qDebug() << "Text of 'speed' " << rect->property("text");
          }
          else
          {
              qDebug() <<  "set fail";
          }
     }else
         {

               qDebug() <<  "not find rect";
         }
快速回复
限100 字节
 
上一个 下一个