本文整理汇总了C++中PythonQtObjectPtr::getVariable方法的典型用法代码示例。如果您正苦于以下问题:C++ PythonQtObjectPtr::getVariable方法的具体用法?C++ PythonQtObjectPtr::getVariable怎么用?C++ PythonQtObjectPtr::getVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PythonQtObjectPtr
的用法示例。
在下文中一共展示了PythonQtObjectPtr::getVariable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testDynamicProperties
void PythonQtTestApi::testDynamicProperties()
{
PythonQtObjectPtr main = PythonQt::self()->getMainModule();
// this fails and should fail, but how could that be tested?
// main.evalScript("obj.testProp = 1");
// create a new dynamic property
main.evalScript("obj.setProperty('testProp','testValue')");
// read the property
QVERIFY(QString("testValue") == main.getVariable("obj.testProp").toString());
// modify and read again
main.evalScript("obj.testProp = 12");
QVERIFY(12 == main.getVariable("obj.testProp").toInt());
// check if dynamic property is in dict
QVERIFY(12 == main.evalScript("obj.__dict__['testProp']", Py_eval_input).toInt());
// check if dynamic property is in introspection
QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), "obj", PythonQt::Anything);
QVERIFY(l.contains("testProp"));
// check with None, previous value expected
main.evalScript("obj.testProp = None");
QVERIFY(12 == main.getVariable("obj.testProp").toInt());
// remove the dynamic property
main.evalScript("obj.setProperty('testProp', None)");
// check if dynamic property is really gone
QStringList l2 = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), "obj", PythonQt::Anything);
QVERIFY(!l2.contains("testProp"));
}
示例2: testProperties
void PythonQtTestApi::testProperties()
{
PythonQtObjectPtr main = PythonQt::self()->getMainModule();
// check for name alias (for backward comp to Qt3)
main.evalScript("obj.name = 'hello'");
QVERIFY(QString("hello") == main.getVariable("obj.name").toString());
main.evalScript("obj.objectName = 'hello2'");
QVERIFY(QString("hello2") == main.getVariable("obj.objectName").toString());
}