查看完整版本: [-- c++ 更新qml 的text  text 没变化 --]

QTCN开发网 -> Qt QML开发 -> c++ 更新qml 的text  text 没变化 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

zzxap 2017-04-13 17:01

c++ 更新qml 的text  text 没变化


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 2017-04-14 08:58
QML 属性绑定有些是不会动态变化的,给 text 一个onTextChanged 信号处理函数,然后更新文本试试看。

cycloveu 2017-04-14 14:38
设计就不应该这么用

zzxap 2017-04-17 15:14
  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 2017-06-08 19:58
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";
         }


查看完整版本: [-- c++ 更新qml 的text  text 没变化 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled