2011-04-05 58 views

回答

1

你真的應該多看看QObject和QMetaObject。

QScriptValue supports the types defined in the ECMA-262 standard: The primitive types, which are Undefined, Null, Boolean, Number, and String; and the Object type. Additionally, Qt Script has built-in support for QVariant, QObject and QMetaObject.

從Qt的QMetaObject頁:

Qt's meta-object system provides the signals and slots mechanism for inter-object communication, run-time type information, and the dynamic property system.

QObject中包含返回兒童爲對象和parent方法的列表的方法children

最重要的是,從pyqt的角度來看,這些是python對象,inspect模塊在我的簡單測試中對它們很好。

你應該能夠與任何這些人建立一個。

FTR,afaik PyQt和Qt是一樣的東西,提供相同的信息。最終,如果它在C++ Qt中工作,它應該在PyQt中工作。

1

是的。您沒有指定是否希望從QtScript或C++中執行此操作。

在腳本引擎可以使用標準的EcmaScript技術在對象上遍歷所有的屬性:

for (var property_name in some_object) { 
    // do something with each property 
} 

這應該包括,例如,導入腳本引擎的QObject上的任何插槽,信號和Q_PROPERTY。它不會包含未標記爲信號,插槽或Q_INVOKABLE的任何C++方法。

在C++中,您可以使用QScriptValueIterator遍歷腳本引擎中任何對象的所有屬性。