Sorry, I haven't noticed your thread earlier. So you say this doesn't work?
#include <QtGui>
Q_OBJECT
public:
public slots:
private:
};
#include "main.moc"
int main(int argc, char **argv){
// QApplication app(argc, argv);
Object o;
o.setList(sl);
qDebug() << o.list();
return 0;
}
#include <QtGui>
class Object : public QObject {
Q_OBJECT
Q_PROPERTY(QStringList list READ list WRITE setList)
public:
const QStringList &list() const { return m_sl; }
public slots:
void setList(const QStringList &sl) { m_sl = sl; }
private:
QStringList m_sl;
};
#include "main.moc"
int main(int argc, char **argv){
// QApplication app(argc, argv);
Object o;
QStringList sl = QStringList() << "a" << "b" << "c";
o.setList(sl);
qDebug() << o.list();
return 0;
}
To copy to clipboard, switch view to plain text mode
It works perfectly fine for me...
Edit: By the way, this also works, if added near the end of main():
QScriptEngine engine;
QScriptValue v = engine.newQObject(&o);
engine.globalObject().setProperty("o", v);
qDebug() << "READ:" << engine.evaluate("o.list").toString();
engine.evaluate("var arr = new Array; arr[0] = 'd'; o.list = arr;").toString();
qDebug() << "WRITE:" << engine.evaluate("o.list").toString();
QScriptEngine engine;
QScriptValue v = engine.newQObject(&o);
engine.globalObject().setProperty("o", v);
qDebug() << "READ:" << engine.evaluate("o.list").toString();
engine.evaluate("var arr = new Array; arr[0] = 'd'; o.list = arr;").toString();
qDebug() << "WRITE:" << engine.evaluate("o.list").toString();
To copy to clipboard, switch view to plain text mode
or even this:
qDebug() << "READ:" << engine.evaluate("o.list").toString();
engine.evaluate("o.list = ['q', 'w', 'e', 'r', 't', 'y'];").toString();
qDebug() << "WRITE:" << engine.evaluate("o.list").toString();
qDebug() << "READ:" << engine.evaluate("o.list").toString();
engine.evaluate("o.list = ['q', 'w', 'e', 'r', 't', 'y'];").toString();
qDebug() << "WRITE:" << engine.evaluate("o.list").toString();
To copy to clipboard, switch view to plain text mode
Bookmarks