本文整理汇总了C++中QScriptValue::setScope方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::setScope方法的具体用法?C++ QScriptValue::setScope怎么用?C++ QScriptValue::setScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::setScope方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDeclarativeView view;
QDeclarativeContext *context = view.rootContext();
context->setContextProperty("backgroundColor",
QColor(Qt::yellow));
KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(view.engine());
kdeclarative.initialize();
//binds things like kconfig and icons
kdeclarative.setupBindings();
//If all gone well, the QScriptEngine has been extracted
QScriptEngine *scriptEngine = kdeclarative.scriptEngine();
Q_ASSERT(scriptEngine);
//Bind a test QObject in the "QtScript way"
QScriptValue global = scriptEngine->globalObject();
TestObject *testObject = new TestObject();
QScriptValue testValue = scriptEngine->newQObject(testObject);
testValue.setScope(global);
global.setProperty("testObject", testValue);
view.setSource(QUrl::fromLocalFile("test.qml"));
view.show();
return app.exec();
}
示例2: counter
//! [72]
QScriptValue counter(QScriptContext *ctx, QScriptEngine *eng)
{
QScriptValue act = ctx->activationObject();
act.setProperty("count", 0);
QScriptValue result = eng->newFunction(counter_inner);
result.setScope(act);
return result;
}