本文整理汇总了C++中QScriptValue::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::toString方法的具体用法?C++ QScriptValue::toString怎么用?C++ QScriptValue::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MagicCore SomeMagicCoreClass;
QScriptEngine scriptEngine;
QScriptValue scriptMagicCore = scriptEngine.newQObject (&SomeMagicCoreClass);
Q_ASSERT (scriptMagicCore.isQObject());
scriptEngine.globalObject().setProperty("Core", scriptMagicCore);
ReadScriptsFromPath(QDir("./scripts/objects/"), scriptEngine);
ReadScriptsFromPath(QDir("./scripts/levels/"), scriptEngine);
char szLine[256];
strcpy(szLine, "");
std::cout << std::endl << "Entering scripting console: " << std::endl;
while (strcmp(szLine, "exit") != 0)
{
// evaluate script line and store return value
QScriptValue retVal = scriptEngine.evaluate(szLine);
if (retVal.isUndefined() == false)
std::cout << "ScriptEngine returns: " << retVal.toString().toStdString() << std::endl;
// read line
strcpy(szLine, "");
std::cin.getline(szLine, 256);
}
/* QScriptValue object = scriptEngine.globalObject().property("testObject");
Q_ASSERT(object.isValid());
QScriptValue SlotMethod = object.property("ExampleSlot1");
Q_ASSERT(SlotMethod.isFunction());
bool bOk = qScriptConnect(&SomeMagicCoreClass, SIGNAL(TestSignal()), object, SlotMethod);
Q_ASSERT(bOk);
QScriptValue object2 = scriptEngine.globalObject().property("testObject2");
Q_ASSERT(object2.isValid());
QScriptValue SlotMethod2 = object2.property("ExampleSlot2");
Q_ASSERT(SlotMethod2.isFunction());
bool bOk2 = qScriptConnect(&SomeMagicCoreClass, SIGNAL(TestSignal()), object2, SlotMethod2);
Q_ASSERT(bOk2);
SomeMagicCoreClass.TriggerSignal();*/
return 0;
/*a.exit(0);
return a.exec();*/
}
示例2: on
QScriptValue PHIBaseItem::on( const QString &name, const QScriptValue &v )
{
if ( !isClientItem() ) return self();
PHIEventHash hash=data( DEventFunctions ).value<PHIEventHash>();
hash.insert( name, v );
qDebug() << "on" << name << v.toString();
switch ( PHIDomEvent::stringToEventType( name ) ) {
case PHIDomEvent::EMouseMove:
case PHIDomEvent::EMouseOut:
case PHIDomEvent::EMouseOver: _flags |= FHasHoverEventHandler; break;
case PHIDomEvent::EClick:
case PHIDomEvent::EDblClick:
case PHIDomEvent::EMouseDown:
case PHIDomEvent::EMouseUp: _flags |= FHasMouseEventHandler; break;
case PHIDomEvent::EKeyDown:
case PHIDomEvent::EKeyPress:
case PHIDomEvent::EKeyUp: _flags |= FHasKeyEventHandler; break;
case PHIDomEvent::EBlur:
case PHIDomEvent::EFocus: _flags |= FHasFocusEventHandler; break;
case PHIDomEvent::EChange: _flags |= FHasChangeEventHandler; break;
case PHIDomEvent::EDrop: _flags |= FHasDropEventHandler; break;
default:;
}
setData( DEventFunctions, qVariantFromValue( hash ) );
return self();
}
示例3: start
void QScriptDebuggerScriptedConsoleCommandJob::start()
{
Q_D(QScriptDebuggerScriptedConsoleCommandJob);
QScriptEngine *engine = d->command->globalObject.engine();
engine->setGlobalObject(d->command->globalObject);
QScriptValueList args;
for (int i = 0; i < d->arguments.size(); ++i)
args.append(QScriptValue(engine, d->arguments.at(i)));
QScriptDebuggerConsoleGlobalObject *global;
global = qobject_cast<QScriptDebuggerConsoleGlobalObject*>(engine->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->execFunction.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();
}
示例4: createMenu
QAction *KWin::AbstractScript::scriptValueToAction(QScriptValue &value, QMenu *parent)
{
QScriptValue titleValue = value.property("text");
QScriptValue checkableValue = value.property("checkable");
QScriptValue checkedValue = value.property("checked");
QScriptValue itemsValue = value.property("items");
QScriptValue triggeredValue = value.property("triggered");
if (!titleValue.isValid()) {
// title not specified - does not make any sense to include
return NULL;
}
const QString title = titleValue.toString();
const bool checkable = checkableValue.isValid() && checkableValue.toBool();
const bool checked = checkable && checkedValue.isValid() && checkedValue.toBool();
// either a menu or a menu item
if (itemsValue.isValid()) {
if (!itemsValue.isArray()) {
// not an array, so cannot be a menu
return NULL;
}
QScriptValue lengthValue = itemsValue.property("length");
if (!lengthValue.isValid() || !lengthValue.isNumber() || lengthValue.toInteger() == 0) {
// length property missing
return NULL;
}
return createMenu(title, itemsValue, parent);
} else if (triggeredValue.isValid()) {
// normal item
return createAction(title, checkable, checked, triggeredValue, parent);
}
return NULL;
}
示例5: thisObject
void tst_QScriptContext::thisObject()
{
QScriptEngine eng;
QScriptValue fun = eng.newFunction(get_thisObject);
eng.globalObject().setProperty("get_thisObject", fun);
{
QScriptValue result = eng.evaluate("get_thisObject()");
QCOMPARE(result.isObject(), true);
QCOMPARE(result.toString(), QString("[object global]"));
}
{
QScriptValue result = eng.evaluate("get_thisObject.apply(new Number(123))");
QCOMPARE(result.isObject(), true);
QCOMPARE(result.toNumber(), 123.0);
}
{
QScriptValue obj = eng.newObject();
eng.currentContext()->setThisObject(obj);
QVERIFY(eng.currentContext()->thisObject().equals(obj));
eng.currentContext()->setThisObject(QScriptValue());
QVERIFY(eng.currentContext()->thisObject().equals(obj));
QScriptEngine eng2;
QScriptValue obj2 = eng2.newObject();
QTest::ignoreMessage(QtWarningMsg, "QScriptContext::setThisObject() failed: cannot set an object created in a different engine");
eng.currentContext()->setThisObject(obj2);
}
}
示例6: js_include
// Currently breaks the lint test, so use with care
static QScriptValue js_include(QScriptContext *context, QScriptEngine *engine)
{
QString path = context->argument(0).toString();
UDWORD size;
char *bytes = NULL;
if (!loadFile(path.toAscii().constData(), &bytes, &size))
{
debug(LOG_ERROR, "Failed to read include file \"%s\"", path.toAscii().constData());
return false;
}
QString source = QString::fromAscii(bytes, size);
free(bytes);
QScriptSyntaxCheckResult syntax = QScriptEngine::checkSyntax(source);
if (syntax.state() != QScriptSyntaxCheckResult::Valid)
{
debug(LOG_ERROR, "Syntax error in include %s line %d: %s",
path.toAscii().constData(), syntax.errorLineNumber(), syntax.errorMessage().toAscii().constData());
return false;
}
context->setActivationObject(engine->globalObject());
context->setThisObject(engine->globalObject());
QScriptValue result = engine->evaluate(source, path);
if (engine->hasUncaughtException())
{
int line = engine->uncaughtExceptionLineNumber();
debug(LOG_ERROR, "Uncaught exception at line %d, include file %s: %s",
line, path.toAscii().constData(), result.toString().toAscii().constData());
return false;
}
return QScriptValue();
}
示例7: exception
/*!
The agent calls this function when an uncaught exception has
occurred.
*/
void QScriptDebuggerBackendPrivate::exception(qint64 scriptId,
const QScriptValue &exception,
bool hasHandler)
{
Q_Q(QScriptDebuggerBackend);
if (ignoreExceptions) {
// don't care (it's caught by us)
return;
}
QScriptDebuggerEvent e(QScriptDebuggerEvent::Exception);
e.setScriptId(scriptId);
e.setFileName(agent->scriptData(scriptId).fileName());
e.setMessage(exception.toString());
e.setHasExceptionHandler(hasHandler);
int lineNumber = -1;
QString fileName;
if (exception.property(QLatin1String("lineNumber")).isNumber())
lineNumber = exception.property(QLatin1String("lineNumber")).toInt32();
if (exception.property(QLatin1String("fileName")).isString())
fileName = exception.property(QLatin1String("fileName")).toString();
if (lineNumber == -1) {
QScriptContextInfo info(q->engine()->currentContext());
lineNumber = info.lineNumber();
fileName = info.fileName();
}
if (lineNumber != -1)
e.setLineNumber(lineNumber);
if (!fileName.isEmpty())
e.setFileName(fileName);
QScriptDebuggerValue value(exception);
e.setScriptValue(value);
q->event(e);
}
示例8: invoke
QString KateTemplateScript::invoke(KateView* view, const QString& functionName, const QString &srcText) {
if(!setView(view))
return QString();
clearExceptions();
QScriptValue myFunction = function(functionName);
if(!myFunction.isValid()) {
return QString();
}
QScriptValueList arguments;
arguments << QScriptValue(m_engine, srcText);
QScriptValue result = myFunction.call(QScriptValue(), arguments);
if(m_engine->hasUncaughtException()) {
displayBacktrace(result, "Error while calling helper function");
return QString();
}
if (result.isNull()) {
return QString();
}
return result.toString();
}
示例9: engineError
QString ScriptManagerPrivate::engineError(const QScriptEnginePtr &scriptEngine)
{
QScriptValue error = scriptEngine->evaluate(QLatin1String("Error"));
if (error.isValid())
return error.toString();
return ScriptManager::tr("Unknown error");
}
示例10: loadScript
void ScriptablePrivate::loadScript(const QString& oName)
{
qDebug() << "Looking for a script " << oName;
XSqlQuery scriptq;
scriptq.prepare("SELECT script_source, script_order"
" FROM script"
" WHERE((script_name=:script_name)"
" AND (script_enabled))"
" ORDER BY script_order;");
scriptq.bindValue(":script_name", oName);
scriptq.exec();
while(scriptq.next())
{
if(engine())
{
QString script = scriptHandleIncludes(scriptq.value("script_source").toString());
QScriptValue result = _engine->evaluate(script, _parent->objectName());
if (_engine->hasUncaughtException())
{
int line = _engine->uncaughtExceptionLineNumber();
qDebug() << "uncaught exception at line" << line << ":" << result.toString();
}
}
else
qDebug() << "could not initialize engine";
}
}
示例11: getSettingsFromScript
QVariant CBDS::getSettingsFromScript(const QString &filename)
{
QFile f(filename);
if (f.open(QIODevice::ReadOnly))
{
QString appcode(f.readAll());
f.close();
QScriptSyntaxCheckResult res = m_engine.checkSyntax(appcode);
if (res.state() != QScriptSyntaxCheckResult::Valid)
{
emit error(QString("SyntaxCheck Failed: Line: %1 Column: %2: %3").arg(res.errorLineNumber()).arg(res.errorColumnNumber()).arg(res.errorMessage()));
return QVariant();
}
QScriptContext *ctx = m_engine.pushContext();
CBJSObject js;
CBObjectBase cbo(&m_engine, m_roomowner);
ctx->activationObject().setProperty("cb", m_engine.newQObject(&cbo));
ctx->activationObject().setProperty("cbjs", m_engine.newQObject(&js));
QScriptValue ret = m_engine.evaluate(appcode, QFileInfo(filename).fileName());
if (ret.isError())
{
emit error(ret.toString());
m_engine.popContext();
return QVariant();
}
m_engine.popContext();
return cbo.getSettingsChoices().toVariant();
}
emit error("Can't open file: " + filename);
return QVariant();
}
示例12: if
PT convert_script_value_f_point<PT>::operator()( QScriptEngine *,
const QScriptValue & args ) const
{
typedef typename point_valtype<PT>::value_type value_type;
value_type x = 0;
value_type y = 0;
QScriptValue obj;
bool smellArray = (args.isArray() || ! args.property("length").isUndefined());
if( smellArray )
{
if(0) qDebug() << "Looks like arguments array.";
obj = args.property(0);
}
else if( args.isObject() )
{
if(0) qDebug() << "Looks like an object.";
obj = args;
}
if( smellArray && !obj.isObject() )
{
if(0) qDebug() << "Trying arguments array.";
x = value_type(args.property(0).toNumber());
y = value_type(args.property(1).toNumber());
}
else
{
if(0) qDebug() << "Trying object x/y:" << obj.toString() << ":" << toSource( obj );
if(0) qDebug() << "obj.property(x).toNumber():"<<obj.property("x").toNumber();
x = value_type(obj.property("x").toNumber());
y = value_type(obj.property("y").toNumber());
}
if(0) qDebug() << "PT:"<<PT(x,y);
return PT(x,y);
}
示例13: to_source_f_object
QString to_source_f<QScriptValue>::operator()( QScriptValue const & x ) const
{
if( x.isUndefined() ) return "undefined";
if( x.isNull() ) return "null";
if(0) qDebug() << "to_source_f<QScriptValue>("<<x.toString()<<")";
#define TODO(A,B,C)
#define DO(IS,T,TO) \
if( x.IS() ) {\
if(0) qDebug() << "to_source_f<QScriptValue>(is-a: "<<# IS<<")"; \
return toSource<T>( x.TO() );\
}
DO(isVariant,QVariant,toVariant); // must come before the others!
DO(isBoolean,bool,toBoolean);
DO(isNumber,qreal,toNumber);
DO(isString,QString,toString);
TODO(isRegExp,QRegExp,toRegExp);
if( x.isArray() || x.isObject() )
{
if(0) qDebug() << "to_source_f<QScriptValue>(is-a: array or object)";
return to_source_f_object()( x );
}
#undef DO
#undef TODO
return QString("undefined");
}
示例14: Initialize
void RexQtScriptModule::Initialize()
{
LogInfo("Module " + Name() + " initializing...");
//XXX hack to have a ref to framework for api funcs
RexQtScript::staticframework = framework_;
QScriptValue res = engine.evaluate("1 + 1;");
LogInfo("Javascript thinks 1 + 1 = " + res.toString().toStdString());
engine.globalObject().setProperty("print", engine.newFunction(RexQtScript::Print));
engine.globalObject().setProperty("loadUI", engine.newFunction(RexQtScript::LoadUI));
engine.evaluate("print('Hello from qtscript');");
char* js = "print('hello from ui loader & handler script!');"
"ui = loadUI('dialog.ui');"
"print(ui);"
"function changed(v) {"
" print('val changed to: ' + v);"
"}"
"print(ui.doubleSpinBox.valueChanged);"
"ui.doubleSpinBox['valueChanged(double)'].connect(changed);"
"print('connecting to doubleSpinBox.valueChanged ok from js (?)');";
engine.evaluate(QString::fromAscii(js));
}
示例15: Generate
QScriptValue CsvHelperWrapper::Generate(const QScriptValue& List, QScriptValue Separator)
{
QStringList a1 = List.toVariant().toStringList();
QChar a2 = Separator.toString()[0];
return QScriptValue(Helper->Generate(a1,a2));
}