本文整理汇总了C++中QScriptValue类的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue类的具体用法?C++ QScriptValue怎么用?C++ QScriptValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QScriptValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: quatFromScriptValue
void quatFromScriptValue(const QScriptValue &object, glm::quat& quat) {
quat.x = object.property("x").toVariant().toFloat();
quat.y = object.property("y").toVariant().toFloat();
quat.z = object.property("z").toVariant().toFloat();
quat.w = object.property("w").toVariant().toFloat();
}
示例2: init
void ScriptEngine::run() {
if (!_isInitialized) {
init();
}
_isRunning = true;
_isFinished = false;
emit runningStateChanged();
QScriptValue result = evaluate(_scriptContents);
if (hasUncaughtException()) {
int line = uncaughtExceptionLineNumber();
qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
clearExceptions();
}
QElapsedTimer startTime;
startTime.start();
int thisFrame = 0;
NodeList* nodeList = NodeList::getInstance();
qint64 lastUpdate = usecTimestampNow();
while (!_isFinished) {
int usecToSleep = (thisFrame++ * SCRIPT_DATA_CALLBACK_USECS) - startTime.nsecsElapsed() / 1000; // nsec to usec
if (usecToSleep > 0) {
usleep(usecToSleep);
}
if (_isFinished) {
break;
}
QCoreApplication::processEvents();
if (_isFinished) {
break;
}
if (_voxelsScriptingInterface.getVoxelPacketSender()->serversExist()) {
// release the queue of edit voxel messages.
_voxelsScriptingInterface.getVoxelPacketSender()->releaseQueuedMessages();
// since we're in non-threaded mode, call process so that the packets are sent
if (!_voxelsScriptingInterface.getVoxelPacketSender()->isThreaded()) {
_voxelsScriptingInterface.getVoxelPacketSender()->process();
}
}
if (_particlesScriptingInterface.getParticlePacketSender()->serversExist()) {
// release the queue of edit voxel messages.
_particlesScriptingInterface.getParticlePacketSender()->releaseQueuedMessages();
// since we're in non-threaded mode, call process so that the packets are sent
if (!_particlesScriptingInterface.getParticlePacketSender()->isThreaded()) {
_particlesScriptingInterface.getParticlePacketSender()->process();
}
}
if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) {
// release the queue of edit voxel messages.
_entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages();
// since we're in non-threaded mode, call process so that the packets are sent
if (!_entityScriptingInterface.getEntityPacketSender()->isThreaded()) {
_entityScriptingInterface.getEntityPacketSender()->process();
}
}
if (_isAvatar && _avatarData) {
const int SCRIPT_AUDIO_BUFFER_SAMPLES = floor(((SCRIPT_DATA_CALLBACK_USECS * SAMPLE_RATE) / (1000 * 1000)) + 0.5);
const int SCRIPT_AUDIO_BUFFER_BYTES = SCRIPT_AUDIO_BUFFER_SAMPLES * sizeof(int16_t);
QByteArray avatarPacket = byteArrayWithPopulatedHeader(PacketTypeAvatarData);
avatarPacket.append(_avatarData->toByteArray());
nodeList->broadcastToNodes(avatarPacket, NodeSet() << NodeType::AvatarMixer);
if (_isListeningToAudioStream || _avatarSound) {
// if we have an avatar audio stream then send it out to our audio-mixer
bool silentFrame = true;
int16_t numAvailableSamples = SCRIPT_AUDIO_BUFFER_SAMPLES;
const int16_t* nextSoundOutput = NULL;
if (_avatarSound) {
const QByteArray& soundByteArray = _avatarSound->getByteArray();
nextSoundOutput = reinterpret_cast<const int16_t*>(soundByteArray.data()
+ _numAvatarSoundSentBytes);
int numAvailableBytes = (soundByteArray.size() - _numAvatarSoundSentBytes) > SCRIPT_AUDIO_BUFFER_BYTES
? SCRIPT_AUDIO_BUFFER_BYTES
: soundByteArray.size() - _numAvatarSoundSentBytes;
numAvailableSamples = numAvailableBytes / sizeof(int16_t);
//.........这里部分代码省略.........
示例3: inputControllerFromScriptValue
void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputController* &out) {
out = qobject_cast<AbstractInputController*>(object.toQObject());
}
示例4: qtscript_QProcess_ExitStatus_toScriptValue
static QScriptValue qtscript_QProcess_ExitStatus_toScriptValue(QScriptEngine *engine, const QProcess::ExitStatus &value)
{
QScriptValue clazz = engine->globalObject().property(QString::fromLatin1("QProcess"));
return clazz.property(qtscript_QProcess_ExitStatus_toStringHelper(value));
}
示例5: qtscript_QProcess_fromScriptValue
static void qtscript_QProcess_fromScriptValue(const QScriptValue &value, QProcess* &out)
{
out = qobject_cast<QProcess*>(value.toQObject());
}
示例6: Q_ASSERT
QScriptValue DefaultScriptClass::property(const QScriptValue& object, const QScriptString& name, uint id)
{
Q_ASSERT(mHandlerInfo->mode() != ScriptHandlerInfo::None);
DataInformation* data = toDataInformation(object);
if (!data)
{
mHandlerInfo->logger()->error() << "could not cast data from" << object.data().toString();
return engine()->currentContext()->throwError(QScriptContext::ReferenceError,
QStringLiteral("Attempting to access an invalid object"));
}
if (name == s_valid)
{
return data->validationSuccessful();
}
else if (name == s_wasAbleToRead)
{
return data->wasAbleToRead();
}
else if (name == s_parent)
{
Q_CHECK_PTR(data->parent());
//parent() cannot be null
if (data->parent()->isTopLevel())
return engine()->nullValue();
return data->parent()->asDataInformation()->toScriptValue(engine(), mHandlerInfo);
}
else if (name == s_datatype)
{
return data->typeName();
}
else if (name == s_updateFunc)
{
return data->updateFunc();
}
else if (name == s_validationFunc)
{
return data->validationFunc();
}
else if (name == s_validationError)
{
return data->validationError();
}
else if (name == s_byteOrder)
{
return ParserUtils::byteOrderToString(data->byteOrder());
}
else if (name == s_name)
{
return data->name();
}
else if (name == s_customTypeName)
{
return data->typeName();
}
else if (name == s_asStringFunc)
{
return data->toStringFunction();
}
QScriptValue other = additionalProperty(data, name, id);
if (other.isValid())
return other;
else
{
data->logError() << "could not find property with name" << name.toString();
return engine()->currentContext()->throwError(QScriptContext::ReferenceError,
QStringLiteral("Cannot read property ") + name.toString());
}
}
示例7: readFile
void tst_QScriptJSTestSuite::runTestFunction(int testIndex)
{
if (!(testIndex & 1)) {
// data
QTest::addColumn<TestRecord>("record");
bool hasData = false;
QString testsShellPath = testsDir.absoluteFilePath("shell.js");
QString testsShellContents = readFile(testsShellPath);
QDir subSuiteDir(subSuitePaths.at(testIndex / 2));
QString subSuiteShellPath = subSuiteDir.absoluteFilePath("shell.js");
QString subSuiteShellContents = readFile(subSuiteShellPath);
QDir testSuiteDir(subSuiteDir);
testSuiteDir.cdUp();
QString suiteJsrefPath = testSuiteDir.absoluteFilePath("jsref.js");
QString suiteJsrefContents = readFile(suiteJsrefPath);
QString suiteShellPath = testSuiteDir.absoluteFilePath("shell.js");
QString suiteShellContents = readFile(suiteShellPath);
QFileInfoList testFileInfos = subSuiteDir.entryInfoList(QStringList() << "*.js", QDir::Files);
foreach (QFileInfo tfi, testFileInfos) {
if ((tfi.fileName() == "shell.js") || (tfi.fileName() == "browser.js"))
continue;
QString abspath = tfi.absoluteFilePath();
QString relpath = testsDir.relativeFilePath(abspath);
QString excludeMessage;
if (isExcludedFile(relpath, &excludeMessage)) {
QTest::newRow(relpath.toLatin1()) << TestRecord(excludeMessage, relpath);
continue;
}
QScriptEngine eng;
QScriptValue global = eng.globalObject();
global.setProperty("print", eng.newFunction(qscript_void));
global.setProperty("quit", eng.newFunction(qscript_quit));
global.setProperty("options", eng.newFunction(qscript_options));
eng.evaluate(testsShellContents, testsShellPath);
if (eng.hasUncaughtException()) {
QStringList bt = eng.uncaughtExceptionBacktrace();
QString err = eng.uncaughtException().toString();
qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
break;
}
eng.evaluate(suiteJsrefContents, suiteJsrefPath);
if (eng.hasUncaughtException()) {
QStringList bt = eng.uncaughtExceptionBacktrace();
QString err = eng.uncaughtException().toString();
qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
break;
}
eng.evaluate(suiteShellContents, suiteShellPath);
if (eng.hasUncaughtException()) {
QStringList bt = eng.uncaughtExceptionBacktrace();
QString err = eng.uncaughtException().toString();
qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
break;
}
eng.evaluate(subSuiteShellContents, subSuiteShellPath);
if (eng.hasUncaughtException()) {
QStringList bt = eng.uncaughtExceptionBacktrace();
QString err = eng.uncaughtException().toString();
qWarning("%s\n%s", qPrintable(err), qPrintable(bt.join("\n")));
break;
}
QScriptValue origTestCaseCtor = global.property("TestCase");
QScriptValue myTestCaseCtor = eng.newFunction(qscript_TestCase);
myTestCaseCtor.setData(origTestCaseCtor);
global.setProperty("TestCase", myTestCaseCtor);
global.setProperty("gTestfile", tfi.fileName());
global.setProperty("gTestsuite", testSuiteDir.dirName());
global.setProperty("gTestsubsuite", subSuiteDir.dirName());
QString testFileContents = readFile(abspath);
// qDebug() << relpath;
eng.evaluate(testFileContents, abspath);
if (eng.hasUncaughtException() && !relpath.endsWith("-n.js")) {
QStringList bt = eng.uncaughtExceptionBacktrace();
QString err = eng.uncaughtException().toString();
qWarning("%s\n%s\n", qPrintable(err), qPrintable(bt.join("\n")));
continue;
}
QScriptValue testcases = global.property("testcases");
if (!testcases.isArray())
testcases = global.property("gTestcases");
int count = testcases.property("length").toInt32();
if (count == 0)
continue;
hasData = true;
QString title = global.property("TITLE").toString();
for (int i = 0; i < count; ++i) {
//.........这里部分代码省略.........
示例8: vec4FromScriptValue
void vec4FromScriptValue(const QScriptValue& object, glm::vec4& vec4) {
vec4.x = object.property("x").toVariant().toFloat();
vec4.y = object.property("y").toVariant().toFloat();
vec4.z = object.property("z").toVariant().toFloat();
vec4.w = object.property("w").toVariant().toFloat();
}
示例9: vec3FromScriptValue
void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3) {
vec3.x = object.property("x").toVariant().toFloat();
vec3.y = object.property("y").toVariant().toFloat();
vec3.z = object.property("z").toVariant().toFloat();
}
示例10: qSizeFToScriptValue
QScriptValue qSizeFToScriptValue(QScriptEngine* engine, const QSizeF& qSizeF) {
QScriptValue obj = engine->newObject();
obj.setProperty("width", qSizeF.width());
obj.setProperty("height", qSizeF.height());
return obj;
}
示例11: qSizeFFromScriptValue
void qSizeFFromScriptValue(const QScriptValue& object, QSizeF& qSizeF) {
qSizeF.setWidth(object.property("width").toVariant().toFloat());
qSizeF.setHeight(object.property("height").toVariant().toFloat());
}
示例12: qURLFromScriptValue
void qURLFromScriptValue(const QScriptValue& object, QUrl& url) {
url = object.toString();
}
示例13: xColorFromScriptValue
void xColorFromScriptValue(const QScriptValue &object, xColor& color) {
color.red = object.property("red").toVariant().toInt();
color.green = object.property("green").toVariant().toInt();
color.blue = object.property("blue").toVariant().toInt();
}
示例14: qRectFromScriptValue
void qRectFromScriptValue(const QScriptValue &object, QRect& rect) {
rect.setX(object.property("x").toVariant().toInt());
rect.setY(object.property("y").toVariant().toInt());
rect.setWidth(object.property("width").toVariant().toInt());
rect.setHeight(object.property("height").toVariant().toInt());
}
示例15: qtscript_QPropertyAnimation_fromScriptValue
static void qtscript_QPropertyAnimation_fromScriptValue(const QScriptValue &value, QPropertyAnimation* &out)
{
out = qobject_cast<QPropertyAnimation*>(value.toQObject());
}