问题
I have a simple need : I have defined a C++ class
class MyClass: public QDeclarativeItem
{
Q_OBJECT
public:
MyClass(QDeclarativeItem * parent=0);
...
private:
QList<QString> mList
}
And of course, I've registered it : qmlRegisterType<MyClass>(...)
I want to access in the QML code to my QList<QString> mList
. How can I do it?
It annoys me as it looks like a simple problem, but I can't find anything about this. (I can create a Q_INVOKABLE slot, but I can't read the results, etc...)
Edit : QML supported Data Types
回答1:
I don't think that QList
is a supported data type for Qt's QML binding. I've had similar problems interfacing between C++ and JavaScript using the QtWebkit Bridge.
If possible, try using a QVariantList
instead of a QList
. Although this is technically a typedef for QList<QVariant>
I think it should work.
回答2:
If you need a custom type in your list (not just strings or other basic types) there's QDeclarativeListProperty for that case.
But it's more complicated, see http://doc.qt.nokia.com/4.7/declarative-tutorials-extending-chapter5-listproperties.html
来源:https://stackoverflow.com/questions/6438157/qml-how-to-read-a-qlist-from-c