Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 求助:Qml如何修改动态创建的对象的属性

求助:Qml如何修改动态创建的对象的属性

Scheduled Pinned Locked Moved Unsolved Chinese
1 Posts 1 Posters 366 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.
  • N Offline
    N Offline
    NixUhs
    wrote on last edited by
    #1

    根据官方教程,在Qml中可以使用createComponent() + createObject()来动态创建组件的对象
    但是要怎么修改这些对象的属性呢
    例如:
    文件dyRec.qml
    Rectangle {
    id: rect
    TextEdit {
    id: rectText
    text: qsTr("Default")
    }
    }

    文件main.qml
    Window {
    id: root
    var dyRect = Qt.createComponent("dyRec.qml")
    var dyRectObj = dyRect.createObject(root)
    //这里我想修改动态对象dyRectObj里的Rectangle下的TextEdit的text,请问要如何修改
    dyRectObj.rectText.text = qsTr("1111") //<--报错
    }

    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