Results 1 to 4 of 4

Thread: problem with setting properties in creating dynamic objects

  1. #1
    Join Date
    Jan 2011
    Location
    Pearl of the Orient Seas
    Posts
    40
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Question problem with setting properties in creating dynamic objects

    Hi,

    Can someone help me regarding the creation of dynamic objects in QML?

    I followed the example on this link http://doc.qt.nokia.com/4.7-snapshot...icobjects.html cause I wanted to create something similar.

    I created the example as is ( Sprite.qml and main.qml ), as well as the javascript file.
    javascript Code:
    1. var component;
    2. var sprite;
    3.  
    4. function createSpriteObjects() {
    5. component = Qt.createComponent("Sprite.qml");
    6. if (component.status == Component.Ready)
    7. finishCreation();
    8. else
    9. component.statusChanged.connect(finishCreation);
    10. }
    11.  
    12. function finishCreation() {
    13. if (component.status == Component.Ready) {
    14. sprite = component.createObject(appWindow, {"x": 100, "y": 100});
    15. if (sprite == null) {
    16. // Error Handling
    17. console.log("Error creating object");
    18. }
    19. } else if (component.status == Component.Error) {
    20. // Error Handling
    21. console.log("Error loading component:", component.errorString());
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Works fine but the setting of properties x and y on line 14 does not work.

    Is this a bug, or is there something I'm missing? Thank you for your help!
    Last edited by wysota; 20th August 2011 at 13:19.

  2. #2
    Join Date
    Jan 2011
    Location
    Pearl of the Orient Seas
    Posts
    40
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: problem with setting properties in creating dynamic objects

    I did a workaround for this that works for me,

    Qt Code:
    1. sprite = component.createObject(appWindow);
    2. sprite.x = 100
    3. sprite.y = 100
    To copy to clipboard, switch view to plain text mode 

    I hope this will help anyone who got stuck in the same situation.

  3. The following user says thank you to aya_lawliet for this useful post:

    frankiefrank (25th September 2011)

  4. #3
    Join Date
    Jan 2011
    Location
    Pearl of the Orient Seas
    Posts
    40
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: problem with setting properties in creating dynamic objects

    There is a slight problem I found regarding the workaround I mentioned above.

    When you set the properties:
    sprite.x = 100
    sprite.y = 100
    This does not mean that the properties are set upon object creation. These properties are set AFTER the object is created.

    Thus, when you add custom property like:
    property string mode: "auto" (in the QML file)

    and updated the value for this in the script:
    sprite.mode = "manual"

    Upon object creation, the mode will still have "auto" value. And after the object is created, the script will then update the mode value to "manual". I just found this out while creating an application.

    I haven't found a solution for setting the property value upon object creation. But when I found the solution, I will post it here.

  5. The following user says thank you to aya_lawliet for this useful post:

    frankiefrank (25th September 2011)

  6. #4
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with setting properties in creating dynamic objects

    Playing with similar implementations, will be happy to know what you learned.

Similar Threads

  1. how to set unknown number of dynamic properties
    By rashmi in forum Qt Programming
    Replies: 0
    Last Post: 15th March 2011, 09:07
  2. Replies: 1
    Last Post: 20th January 2011, 17:17
  3. QUiLoader Problem: No Dynamic Properties Support
    By kalli in forum Qt Programming
    Replies: 0
    Last Post: 28th June 2010, 21:51
  4. dynamic properties
    By Hogwarts in forum Qt Programming
    Replies: 1
    Last Post: 3rd May 2010, 16:37
  5. How avoid translation of dynamic properties
    By thomas_-_s in forum Qt Tools
    Replies: 1
    Last Post: 19th October 2008, 22:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.