[Qt-qml] no basic property define confuse

罗军 luoj at neusoft.com
Thu Sep 30 02:57:46 CEST 2010


Thank you.

I understand, but I confuse this syntax problem.

Rectangle {
    id: rootRectangle
    width: 300
    height: 300

    property Item myProperty: Text {
        parent: rootRectangle                  // ------ It works.
        id: myText
        text: "foobar"
        font.bold: true
        font.pixelSize: 20
        x: 40
        y: 40
    }
}



From: Eduardo Fleury 
Sent: Thursday, September 30, 2010 4:52 AM
To: 罗军 
Cc: qt-qml at trolltech.com 
Subject: Re: [Qt-qml] no basic property define confuse


Sorry I have to replying to myself once again. :-)

Caio and Daker here at the office pointed a mistake in my previous answer.


On Wed, Sep 29, 2010 at 3:52 PM, Eduardo Fleury <eduardo.fleury at openbossa.org> wrote:

  or else, use a Loader to show it somewhere else:

  Rectangle {
      Loader {
          delegate: myProperty   // assuming this is an initialized property of type Text
      }
  }



This is wrong in two ways:
1) The name of the property I intended to say is "sourceComponent", not "delegate".
2) As the name implies, it expects a Component, not a an Item (or Text). You can make "myProperty" of the type "Component" and that will work, but in that case you won't create the Text object yourself, instead will will be defining a Component and creating an instance of Text dynamically using Loader. (See Component and Loader docs for more info).


The short answer to make your first item be shown on the screen is to set its parent accordingly by doing:

myText1.parent = someOtherItemId

See attached example.

BR,
Eduardo
---------------------------------------------------------------------------------------------------
Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) 
is intended only for the use of the intended recipient and may be confidential and/or privileged of 
Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is 
not the intended recipient, unauthorized use, forwarding, printing,  storing, disclosure or copying 
is strictly prohibited, and may be unlawful.If you have received this communication in error,please 
immediately notify the sender by return e-mail, and delete the original message and all copies from 
your system. Thank you. 
---------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100930/02b7ee15/attachment.html 


More information about the Qt-qml mailing list