Results 1 to 2 of 2

Thread: Dynamic creation of list<transform>

  1. #1
    Join Date
    Jun 2006
    Posts
    43
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Dynamic creation of list<transform>

    I am attempting to dynamically create a list<Transform> object in javascript in order to set a transform property.

    This is the minimum compilable example I know how to make at the moment.

    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Controls 1.4
    3.  
    4. ApplicationWindow {
    5. visible: true
    6. width: 640
    7. height: 480
    8.  
    9. Component.onCompleted: {
    10. console.log("Trying to create a transform list");
    11. var newObject = Qt.createQmlObject(
    12. 'import QtQuick 2.5; [ Scale { xScale: 1; yScale: 1 } ]',
    13. this,
    14. 'newObject');
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    It gives the error...

    Qt Code:
    1. qrc:/main.qml:12: Error: Qt.createQmlObject(): failed to create object:
    2. qrc:/newObject:1:29: Expected token `,'
    3. qrc:/newObject:1:40: Expected token `}'
    To copy to clipboard, switch view to plain text mode 

    Where am I stuck?

    At some point, I'm going to need to append to this list, preferably in QML context and not javascript.
    Is the following going to work? Will this nest a list in a list or will it extend the original list?

    Qt Code:
    1. transform: [ existingTransformList, Translate { x: 5, y: 5} ]
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic creation of list<transform>

    Quote Originally Posted by Mookie View Post
    Where am I stuck?
    The string you pass to createQmlObject() doesn't look like it is valid QML.
    Especially the [] brackets seem off, the only valid "top level" tokens are imports and a single Element type.
    Have you tried putting it into a separate QML file and load it with qmlscene?

    Quote Originally Posted by Mookie View Post
    Is the following going to work? Will this nest a list in a list or will it extend the original list?
    That looks to me like creating a list that has two values.
    If "existingTransformList" is a list itself, then the two type are probably not compatible.

    Cheers,
    _

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

    Mookie (27th March 2016)

Similar Threads

  1. Replies: 10
    Last Post: 1st August 2014, 07:50
  2. QMetaType dynamic object creation and initialization
    By d_stranz in forum Qt Programming
    Replies: 5
    Last Post: 24th July 2014, 11:12
  3. Dynamic creation of widget with N images
    By davethomaspilot in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2014, 13:45
  4. Aim: Creation of list during runtime
    By QtAlexander in forum Newbie
    Replies: 2
    Last Post: 16th November 2010, 21:19
  5. Dynamic widget creation from an XML-like file
    By ttvo in forum Qt Programming
    Replies: 2
    Last Post: 1st June 2009, 23:15

Tags for this Thread

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.