本文整理汇总了C++中QScriptValue::toBoolean方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::toBoolean方法的具体用法?C++ QScriptValue::toBoolean怎么用?C++ QScriptValue::toBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::toBoolean方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: breakpointDataFromScriptValue
static void breakpointDataFromScriptValue(const QScriptValue &in, QScriptBreakpointData &out)
{
QScriptValue scriptId = in.property(QString::fromLatin1("scriptId"));
if (scriptId.isValid())
out.setScriptId((qint64)scriptId.toNumber());
out.setFileName(in.property(QString::fromLatin1("fileName")).toString());
out.setLineNumber(in.property(QString::fromLatin1("lineNumber")).toInt32());
QScriptValue enabled = in.property(QString::fromLatin1("enabled"));
if (enabled.isValid())
out.setEnabled(enabled.toBoolean());
QScriptValue singleShot = in.property(QString::fromLatin1("singleShot"));
if (singleShot.isValid())
out.setSingleShot(singleShot.toBoolean());
out.setIgnoreCount(in.property(QString::fromLatin1("ignoreCount")).toInt32());
out.setCondition(in.property(QString::fromLatin1("condition")).toString());
}
示例2: setProperty
void TimerClass::setProperty(QScriptValue &object,
const QScriptString &name,
uint /*id*/, const QScriptValue &value) {
QTimer *timer = qscriptvalue_cast<QTimer*>(object.data());
qDebug() << "Value after de-varianting setProperty: " << timer << name;
if (!timer)
return;
if (name == _interval) {
timer->setInterval(value.toInt32());
} else if (name == _singleShot) {
timer->setSingleShot(value.toBoolean());
}
}
示例3: positionChange
/*!
\reimp
*/
void QScriptDebuggerAgent::positionChange(qint64 scriptId,
int lineNumber, int columnNumber)
{
Q_D(QScriptDebuggerAgent);
if (engine()->processEventsInterval() == -1) {
// see if it's time to call processEvents()
if ((++d->statementCounter % 25000) == 0) {
if (!d->processEventsTimer.isNull()) {
if (d->processEventsTimer.elapsed() > 30) {
QCoreApplication::processEvents();
d->processEventsTimer.restart();
}
} else {
d->processEventsTimer.start();
}
}
}
// check breakpoints
{
QList<int> lst = d->resolvedBreakpoints.value(scriptId);
for (int i = 0; i < lst.size(); ++i) {
int id = lst.at(i);
QScriptBreakpointData &data = d->breakpoints[id];
if (!data.isEnabled())
continue;
if (data.lineNumber() != lineNumber)
continue;
if (!data.condition().isEmpty()) {
// ### careful, evaluate() can cause an exception
// ### disable callbacks in nested evaluate?
QScriptDebuggerAgentPrivate::State was = d->state;
d->state = QScriptDebuggerAgentPrivate::NoState;
QScriptValue ret = engine()->evaluate(
data.condition(),
QString::fromLatin1("Breakpoint %0 condition checker").arg(id));
if (!ret.isError())
d->state = was;
if (!ret.toBoolean())
continue;
}
if (!data.hit())
continue;
d->hitBreakpointId = id;
d->state = QScriptDebuggerAgentPrivate::BreakpointState;
}
}
switch (d->state) {
case QScriptDebuggerAgentPrivate::NoState:
case QScriptDebuggerAgentPrivate::SteppingOutState:
case QScriptDebuggerAgentPrivate::ReturningByForceState:
// Do nothing
break;
case QScriptDebuggerAgentPrivate::SteppingIntoState:
if (--d->stepCount == 0) {
d->state = QScriptDebuggerAgentPrivate::NoState;
if (d->backend)
d->backend->stepped(scriptId, lineNumber, columnNumber, QScriptValue());
}
break;
case QScriptDebuggerAgentPrivate::SteppingOverState:
if ((d->stepDepth > 0) || (--d->stepCount != 0))
break;
// fallthrough
case QScriptDebuggerAgentPrivate::SteppedOverState:
d->state = QScriptDebuggerAgentPrivate::NoState;
if (d->backend)
d->backend->stepped(scriptId, lineNumber, columnNumber, d->stepResult);
break;
case QScriptDebuggerAgentPrivate::SteppedOutState:
d->state = QScriptDebuggerAgentPrivate::NoState;
if (d->backend)
d->backend->stepped(scriptId, lineNumber, columnNumber, d->stepResult);
break;
case QScriptDebuggerAgentPrivate::RunningToLocationState:
if (((lineNumber == d->targetLineNumber) || (d->targetLineNumber == -1))
&& (scriptId == d->targetScriptId)) {
d->state = QScriptDebuggerAgentPrivate::NoState;
if (d->backend)
d->backend->locationReached(scriptId, lineNumber, columnNumber);
}
break;
case QScriptDebuggerAgentPrivate::InterruptingState:
d->state = QScriptDebuggerAgentPrivate::NoState;
if (d->backend)
d->backend->interrupted(scriptId, lineNumber, columnNumber);
break;
case QScriptDebuggerAgentPrivate::BreakpointState:
d->state = QScriptDebuggerAgentPrivate::NoState;
if (d->backend)
//.........这里部分代码省略.........
示例4: extension
void tst_QScriptClass::extension()
{
QScriptEngine eng;
{
TestClass cls(&eng);
cls.setCallableMode(TestClass::NotCallable);
QVERIFY(!cls.supportsExtension(QScriptClass::Callable));
QVERIFY(!cls.supportsExtension(QScriptClass::HasInstance));
QScriptValue obj = eng.newObject(&cls);
QVERIFY(!obj.call().isValid());
QCOMPARE((int)cls.lastExtensionType(), -1);
QVERIFY(!obj.instanceOf(obj));
QCOMPARE((int)cls.lastExtensionType(), -1);
}
// Callable
{
TestClass cls(&eng);
cls.setCallableMode(TestClass::CallableReturnsSum);
QVERIFY(cls.supportsExtension(QScriptClass::Callable));
QScriptValue obj = eng.newObject(&cls);
eng.globalObject().setProperty("obj", obj);
obj.setProperty("one", QScriptValue(&eng, 1));
obj.setProperty("two", QScriptValue(&eng, 2));
obj.setProperty("three", QScriptValue(&eng, 3));
// From C++
cls.clearReceivedArgs();
{
QScriptValueList args;
args << QScriptValue(&eng, 4) << QScriptValue(&eng, 5);
QScriptValue ret = obj.call(obj, args);
QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
QVERIFY(ret.isNumber());
QCOMPARE(ret.toNumber(), qsreal(15));
}
// From JS
cls.clearReceivedArgs();
{
QScriptValue ret = eng.evaluate("obj(4, 5)");
QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
QVERIFY(ret.isNumber());
QCOMPARE(ret.toNumber(), qsreal(15));
}
cls.setCallableMode(TestClass::CallableReturnsArgument);
// From C++
cls.clearReceivedArgs();
{
QScriptValue ret = obj.call(obj, QScriptValueList() << 123);
QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
QVERIFY(ret.isNumber());
QCOMPARE(ret.toInt32(), 123);
}
cls.clearReceivedArgs();
{
QScriptValue ret = obj.call(obj, QScriptValueList() << true);
QCOMPARE(cls.lastExtensionType(), QScriptClass::Callable);
QCOMPARE(cls.lastExtensionArgument().userType(), qMetaTypeId<QScriptContext*>());
QVERIFY(ret.isBoolean());
QCOMPARE(ret.toBoolean(), true);
}
{
QScriptValue ret = obj.call(obj, QScriptValueList() << QString::fromLatin1("ciao"));
QVERIFY(ret.isString());
QCOMPARE(ret.toString(), QString::fromLatin1("ciao"));
}
{
QScriptValue objobj = eng.newObject();
QScriptValue ret = obj.call(obj, QScriptValueList() << objobj);
QVERIFY(ret.isObject());
QVERIFY(ret.strictlyEquals(objobj));
}
{
QScriptValue ret = obj.call(obj, QScriptValueList() << QScriptValue());
QVERIFY(ret.isUndefined());
}
// From JS
cls.clearReceivedArgs();
{
QScriptValue ret = eng.evaluate("obj(123)");
QVERIFY(ret.isNumber());
QCOMPARE(ret.toInt32(), 123);
}
cls.setCallableMode(TestClass::CallableReturnsInvalidVariant);
{
QScriptValue ret = obj.call(obj);
QVERIFY(ret.isUndefined());
}
cls.setCallableMode(TestClass::CallableReturnsThisObject);
// From C++
{
QScriptValue ret = obj.call(obj);
QVERIFY(ret.isObject());
QVERIFY(ret.strictlyEquals(obj));
}
//.........这里部分代码省略.........