本文整理汇总了C++中QScriptEngine::toScriptValue方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptEngine::toScriptValue方法的具体用法?C++ QScriptEngine::toScriptValue怎么用?C++ QScriptEngine::toScriptValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptEngine
的用法示例。
在下文中一共展示了QScriptEngine::toScriptValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleResponse
void QScriptDebuggerScriptedConsoleCommandJob::handleResponse(
const QScriptDebuggerResponse &response,
int commandId)
{
Q_D(QScriptDebuggerScriptedConsoleCommandJob);
// ### generalize
QScriptEngine *engine = d->command->globalObject.engine();
engine->setGlobalObject(d->command->globalObject);
QScriptValueList args;
args.append(engine->toScriptValue(response));
args.append(QScriptValue(engine, commandId));
QScriptDebuggerConsoleGlobalObject *global;
global = qobject_cast<QScriptDebuggerConsoleGlobalObject*>(d->command->globalObject.toQObject());
Q_ASSERT(global != 0);
global->setScheduler(this);
global->setResponseHandler(this);
global->setMessageHandler(d->messageHandler);
global->setConsole(d->console);
d->commandCount = 0;
QScriptValue ret = d->command->responseFunction.call(QScriptValue(), args);
global->setScheduler(0);
global->setResponseHandler(0);
global->setMessageHandler(0);
global->setConsole(0);
if (ret.isError()) {
qWarning("*** internal error: %s", qPrintable(ret.toString()));
}
if (d->commandCount == 0)
finish();
}
示例2: loadScriptStates
bool loadScriptStates(const char *filename)
{
WzConfig ini(filename);
QStringList list = ini.childGroups();
debug(LOG_SAVE, "Loading script states for %d script contexts", scripts.size());
for (int i = 0; i < list.size(); ++i)
{
ini.beginGroup(list[i]);
int player = ini.value("me").toInt();
QString scriptName = ini.value("scriptName").toString();
QScriptEngine *engine = findEngineForPlayer(player, scriptName);
if (engine && list[i].startsWith("triggers_"))
{
timerNode node;
node.player = player;
node.ms = ini.value("ms").toInt();
node.frameTime = ini.value("frame").toInt();
node.engine = engine;
debug(LOG_SAVE, "Registering trigger %d for player %d, script %s",
i, node.player, scriptName.toUtf8().constData());
node.function = ini.value("function").toString();
node.baseobj = ini.value("baseobj", -1).toInt();
node.type = (timerType)ini.value("type", TIMER_REPEAT).toInt();
timers.push_back(node);
}
else if (engine && list[i].startsWith("globals_"))
{
QStringList keys = ini.childKeys();
debug(LOG_SAVE, "Loading script globals for player %d, script %s -- found %d values",
player, scriptName.toUtf8().constData(), keys.size());
for (int j = 0; j < keys.size(); ++j)
{
engine->globalObject().setProperty(keys.at(j), engine->toScriptValue(ini.value(keys.at(j))));
}
}
else if (engine && list[i].startsWith("groups_"))
{
QStringList keys = ini.childKeys();
for (int j = 0; j < keys.size(); ++j)
{
QStringList values = ini.value(keys.at(j)).toStringList();
bool ok = false; // check if number
int droidId = keys.at(j).toInt(&ok);
for (int k = 0; ok && k < values.size(); k++)
{
int groupId = values.at(k).toInt();
loadGroup(engine, groupId, droidId);
}
}
}
ini.endGroup();
}
return true;
}
示例3: main
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QStringList paths = QStringList() << QCoreApplication::applicationDirPath() + "/../../plugins";
app.setLibraryPaths(paths);
QScriptEngine *engine = new QScriptEngine();
QScriptValue global = engine->globalObject();
// add the qt object
global.setProperty("qs", engine->newObject());
// add a 'script' object
QScriptValue script = engine->newObject();
global.property("qs").setProperty("script", script);
// add a 'system' object
QScriptValue system = engine->newObject();
global.property("qs").setProperty("system", system);
// add os information to qt.system.os
#ifdef Q_OS_WIN32
QScriptValue osName = engine->toScriptValue(QString("windows"));
#elif defined(Q_OS_LINUX)
QScriptValue osName = engine->toScriptValue(QString("linux"));
#elif defined(Q_OS_MAC)
QScriptValue osName = engine->toScriptValue(QString("mac"));
#elif defined(Q_OS_UNIX)
QScriptValue osName = engine->toScriptValue(QString("unix"));
#endif
system.setProperty("os", osName);
// add environment variables to qt.system.env
QMap<QString,QVariant> envMap;
QStringList envList = QProcess::systemEnvironment();
foreach (const QString &entry, envList) {
QStringList keyVal = entry.split('=');
if (keyVal.size() == 1)
envMap.insert(keyVal.at(0), QString());
else
envMap.insert(keyVal.at(0), keyVal.at(1));
}
示例4: loadScriptStates
bool loadScriptStates(const char *filename)
{
WzConfig ini(filename);
QStringList list = ini.childGroups();
debug(LOG_SAVE, "Loading script states for %d script contexts", scripts.size());
for (int i = 0; i < list.size(); ++i)
{
if (list[i].startsWith("triggers_"))
{
ini.beginGroup(list[i]);
timerNode node;
node.player = ini.value("player").toInt();
node.ms = ini.value("ms").toInt();
node.frameTime = ini.value("frame").toInt();
debug(LOG_SAVE, "Registering trigger %d for player %d", i, node.player);
node.engine = findEngineForPlayer(node.player);
if (node.engine)
{
node.function = ini.value("function").toString();
node.baseobj = ini.value("baseobj", -1).toInt();
node.type = (timerType)ini.value("type", TIMER_REPEAT).toInt();
timers.push_back(node);
}
ini.endGroup();
}
else if (list[i].startsWith("globals_"))
{
ini.beginGroup(list[i]);
int player = ini.value("me").toInt();
QStringList keys = ini.childKeys();
debug(LOG_SAVE, "Loading script globals for player %d -- found %d values", player, keys.size());
QScriptEngine *engine = findEngineForPlayer(player);
if (engine)
{
for (int j = 0; j < keys.size(); ++j)
{
engine->globalObject().setProperty(keys.at(j), engine->toScriptValue(ini.value(keys.at(j))));
}
}
ini.endGroup();
}
}
return true;
}
示例5: rectifier
//! [55]
QScriptValue rectifier(QScriptContext *ctx, QScriptEngine *eng)
{
QRectF magicRect = qscriptvalue_cast<QRectF>(ctx->callee().data());
QRectF sourceRect = qscriptvalue_cast<QRectF>(ctx->argument(0));
return eng->toScriptValue(sourceRect.intersected(magicRect));
}
示例6: QPoint_ctor
//! [44]
QScriptValue QPoint_ctor(QScriptContext *context, QScriptEngine *engine)
{
int x = context->argument(0).toInt32();
int y = context->argument(1).toInt32();
return engine->toScriptValue(QPoint(x, y));
}