Results 1 to 1 of 1

Thread: QtScript: Passing an array of objects to C++

  1. #1
    Join Date
    Apr 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QtScript: Passing an array of objects to C++

    Hi,

    I want to pass an array of objects from my QtScript to C++ but I have not been able to figure out how to achieve this. As soon as I create an array, the elements inside it are converted to strings before I can access them.

    This is what I have been trying so far:

    class myObject : public QObject, public QScriptable
    {
    Q_OBJECT

    public Q_SLOTS:
    void test(QVariantList list);
    };

    void myObject::test(QVariantList list)
    {
    for (QVariantList::const_iterator it = list.begin(); it != list.end(); ++it) {
    QVariant element = *it;

    qDebug() << element.typeName() << element.toString();

    if (element.canConvert<QVariantMap>()) {
    // Not getting here
    }
    }
    }

    The following script

    myObject.test([{"foo": 1, "bar": 2}, {"baaz": 3, "baaaz": 4}]);

    prints

    "QString" "[object Object]"
    "QString" "[object Object]"

    I am using Qt 4.6...
    Last edited by Plow; 16th April 2010 at 14:46.

Similar Threads

  1. Accessing array in both C++ and QtScript
    By abernat in forum Qt Programming
    Replies: 10
    Last Post: 6th September 2009, 22:21
  2. Lumina GLSL IDE based on QtScript and dynamic Objects
    By oc2k1 in forum Qt-based Software
    Replies: 0
    Last Post: 12th August 2008, 04:12
  3. Problems passing an array of pointers to objects to a function
    By Valheru in forum General Programming
    Replies: 16
    Last Post: 30th June 2008, 00:11
  4. Replies: 2
    Last Post: 16th April 2008, 10:31
  5. QtScript : passing array as argument into function
    By derek_r in forum Qt Programming
    Replies: 4
    Last Post: 27th October 2007, 10:46

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.