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

Wilhelm wilhelm.meier at fh-kl.de
Wed Jan 19 15:33:24 CET 2011


Hi Noam,

Am 19.01.2011 10:54, schrieb noam.rosenthal at nokia.com:
> 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.

thanks for that advice! I can now map attributes from QList<> to the
qtscript object, e.g. i can use a length attribute in qtscript. Good!

The next question is how get the list printed or get a an usable
[]-operator, e.g. in qtscript:

iconlist = test.list();
print(iconlist); // should print a textual representation
                 // (as with QStringList)

for(i = 0; i < iconlist.length; i++) { // as with QStringList
   print(iconlist[i]);
}

Do I have to make a wrapper / prototype class with Q_INVOKABLE QString
toString() and Q_INVOKABLE QSize operator[](int) ?



> 
> 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


-- 
Wilhelm




More information about the Qt-interest-old mailing list