[Qt-interest] QtScript: Making QList<QIcon> a scriptable type (like QStringList), how?

noam.rosenthal at nokia.com noam.rosenthal at nokia.com
Wed Jan 19 10:54:29 CET 2011


Hi Wilhelm

Try http://doc.qt.nokia.com/4.7/qscriptengine.html#qScriptRegisterMetaType
You need to let QtScript know how to special case QList<QIcon> or any other custom type.
The example in that doc should be similar to what you're trying to do.

No'am

________________________________________
From: qt-interest-bounces+noam.rosenthal=nokia.com at qt.nokia.com [qt-interest-bounces+noam.rosenthal=nokia.com at qt.nokia.com] On Behalf Of ext Wilhelm [wilhelm.meier at fh-kl.de]
Sent: Wednesday, January 19, 2011 1:38 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] QtScript: Making QList<QIcon> a scriptable type (like QStringList), how?

Hi,

I like to make QList<QIcon> scriptable like QStringList, but I can't
figure out how to do that.

E.g., I have a

class Test : public QObject {
...

  Q_INVOKABLE QStringList list1() {
    return list(); // returns a QStringlist
  }
...
};

If I make an instance of this class available in the qtscript-engine as
say object "test", then I can retrieve the stringlist:

(in qtscript):

sl = test.list1();
print(sl);
for(s in sl) {
  print(sl[s]);
}

Now I want to do the same with a QList<QIcon> or similar. Say in the
class Test as above:

  Q_INVOKABLE QList<QIcon> list2() {
        return QList<QIcon> << QIcon() << QIcon();
  }

and in qtscript should be possible:

il = test.list2();
icon = il[0];
print(icon.width);


Well, I experimented and googled, but I can't find the right way.

Any hints?

--
Wilhelm

_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list