本文整理汇总了C++中QQmlError类的典型用法代码示例。如果您正苦于以下问题:C++ QQmlError类的具体用法?C++ QQmlError怎么用?C++ QQmlError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QQmlError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: c
void tst_qqmlexpression::scriptString()
{
qmlRegisterType<TestObject>("Test", 1, 0, "TestObject");
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("scriptString.qml"));
TestObject *testObj = qobject_cast<TestObject*>(c.create());
QVERIFY(testObj != 0);
QQmlScriptString script = testObj->scriptString();
QVERIFY(!script.isEmpty());
QQmlExpression expression(script);
QVariant value = expression.evaluate();
QCOMPARE(value.toInt(), 15);
QQmlScriptString scriptError = testObj->scriptStringError();
QVERIFY(!scriptError.isEmpty());
//verify that the expression has the correct error location information
QQmlExpression expressionError(scriptError);
QVariant valueError = expressionError.evaluate();
QVERIFY(!valueError.isValid());
QVERIFY(expressionError.hasError());
QQmlError error = expressionError.error();
QCOMPARE(error.url(), c.url());
QCOMPARE(error.line(), 8);
}
示例2: error
/*!
Reports an error with the given \a description.
An error is generated referring to the \a location in the source file.
*/
void QQmlCustomParser::error(const QV4::CompiledData::Location &location, const QString &description)
{
QQmlError error;
error.setLine(location.line);
error.setColumn(location.column);
error.setDescription(description);
exceptions << error;
}
示例3: qmlErrorToString
static QString qmlErrorToString(const QQmlError &error)
{
return QStringLiteral("%1:%2:%3: %4")
.arg(error.url().toString())
.arg(error.line())
.arg(error.column())
.arg(error.description());
}
示例4: recordError
void QmcTypeCompiler::recordError(const QV4::CompiledData::Location& location, const QString& description)
{
QQmlError error;
error.setLine(location.line);
error.setColumn(location.column);
error.setUrl(compiledData->url);
error.setDescription(description);
recordError(error);
}
示例5: module
CompiledData::CompilationUnit *Script::precompile(ExecutionEngine *engine, const QUrl &url, const QString &source, QList<QQmlError> *reportedErrors)
{
using namespace QQmlJS;
using namespace QQmlJS::AST;
QQmlJS::V4IR::Module module(engine->debugger != 0);
QQmlJS::Engine ee;
QQmlJS::Lexer lexer(&ee);
lexer.setCode(source, /*line*/1, /*qml mode*/true);
QQmlJS::Parser parser(&ee);
parser.parseProgram();
QList<QQmlError> errors;
foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) {
if (m.isWarning()) {
qWarning("%s:%d : %s", qPrintable(url.toString()), m.loc.startLine, qPrintable(m.message));
continue;
}
QQmlError error;
error.setUrl(url);
error.setDescription(m.message);
error.setLine(m.loc.startLine);
error.setColumn(m.loc.startColumn);
errors << error;
}
if (!errors.isEmpty()) {
if (reportedErrors)
*reportedErrors << errors;
return 0;
}
Program *program = AST::cast<Program *>(parser.rootNode());
if (!program) {
// if parsing was successful, and we have no program, then
// we're done...:
return 0;
}
QQmlJS::Codegen cg(/*strict mode*/false);
cg.generateFromProgram(url.toString(), source, program, &module, QQmlJS::Codegen::EvalCode);
errors = cg.errors();
if (!errors.isEmpty()) {
if (reportedErrors)
*reportedErrors << cg.errors();
return 0;
}
Compiler::JSUnitGenerator jsGenerator(&module);
QScopedPointer<QQmlJS::EvalInstructionSelection> isel(engine->iselFactory->create(QQmlEnginePrivate::get(engine), engine->executableAllocator, &module, &jsGenerator));
isel->setUseFastLookups(false);
return isel->compile();
}
示例6: foreach
foreach(QQmlError warning, warnings)
{
QString url;
if (warning.url().isLocalFile())
url = warning.url().toLocalFile();
else
url = warning.url().toString();
qCWarning(sambaLogQml, "%s:%d: %s", url.toLocal8Bit().constData(),
warning.line(), warning.description().toLocal8Bit().constData());
}
示例7: scope
QV4::ReturnedValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, QObject *qmlScope,
const QString &code, const QString &filename, quint16 line,
QV4::PersistentValue *qmlscope)
{
QQmlEngine *engine = ctxt->engine;
QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine());
QV4::ExecutionContext *ctx = v4->currentContext();
QV4::Scope scope(v4);
QV4::ScopedObject qmlScopeObject(scope, QV4::QmlContextWrapper::qmlScope(ep->v8engine(), ctxt, qmlScope));
QV4::Script script(v4, qmlScopeObject, code, filename, line);
QV4::ScopedValue result(scope);
script.parse();
if (!v4->hasException)
result = script.qmlBinding();
if (v4->hasException) {
QQmlError error = QV4::ExecutionEngine::catchExceptionAsQmlError(ctx);
if (error.description().isEmpty())
error.setDescription(QLatin1String("Exception occurred during function evaluation"));
if (error.line() == -1)
error.setLine(line);
if (error.url().isEmpty())
error.setUrl(QUrl::fromLocalFile(filename));
error.setObject(qmlScope);
ep->warning(error);
return QV4::Encode::undefined();
}
if (qmlscope)
*qmlscope = qmlScopeObject;
return result.asReturnedValue();
}
示例8: url
QList<QQmlError> QQmlDirParser::errors(const QString &uri) const
{
QUrl url(uri);
QList<QQmlError> errors;
for (int i = 0; i < _errors.size(); ++i) {
const QQmlJS::DiagnosticMessage &msg = _errors.at(i);
QQmlError e;
QString description = msg.message;
description.replace(QLatin1String("$$URI$$"), uri);
e.setDescription(description);
e.setUrl(url);
e.setLine(msg.loc.startLine);
e.setColumn(msg.loc.startColumn);
errors << e;
}
return errors;
}
示例9: f
bool Compiler::compile(const QString &url, const QString &outputFile)
{
// open output file
QFile f(outputFile);
if (!f.open(QFile::WriteOnly | QFile::Truncate)) {
QQmlError error;
error.setDescription("Could not open file for writing");
error.setUrl(QUrl(outputFile));
return false;
}
QDataStream out(&f);
bool ret = compile(url, out);
f.close();
return ret;
}
示例10: Q_D
void QQuickWindowQmlImpl::setWindowVisibility()
{
Q_D(QQuickWindowQmlImpl);
if (transientParent() && !transientParent()->isVisible())
return;
if (sender()) {
disconnect(transientParent(), &QWindow::visibleChanged, this,
&QQuickWindowQmlImpl::setWindowVisibility);
}
// We have deferred window creation until we have the full picture of what
// the user wanted in terms of window state, geometry, visibility, etc.
if ((d->visibility == Hidden && d->visible) || (d->visibility > AutomaticVisibility && !d->visible)) {
QQmlData *data = QQmlData::get(this);
Q_ASSERT(data && data->context);
QQmlError error;
error.setObject(this);
const QQmlContextData* urlContext = data->context;
while (urlContext && urlContext->url().isEmpty())
urlContext = urlContext->parent;
error.setUrl(urlContext ? urlContext->url() : QUrl());
QString objectId = data->context->findObjectId(this);
if (!objectId.isEmpty())
error.setDescription(QCoreApplication::translate("QQuickWindowQmlImpl",
"Conflicting properties 'visible' and 'visibility' for Window '%1'").arg(objectId));
else
error.setDescription(QCoreApplication::translate("QQuickWindowQmlImpl",
"Conflicting properties 'visible' and 'visibility'"));
QQmlEnginePrivate::get(data->context->engine)->warning(error);
}
if (d->visibility == AutomaticVisibility) {
setWindowState(QGuiApplicationPrivate::platformIntegration()->defaultWindowState(flags()));
setVisible(d->visible);
} else {
setVisibility(d->visibility);
}
}
示例11: Q_D
bool Compiler::addImport(const QV4::CompiledData::Import *import, QList<QQmlError> *errors)
{
Q_D(Compiler);
const QString &importUri = stringAt(import->uriIndex);
const QString &importQualifier = stringAt(import->qualifierIndex);
if (import->type == QV4::CompiledData::Import::ImportScript) {
// TBD: qqmltypeloader.cpp:1320
QmlCompilation::ScriptReference scriptRef;
scriptRef.location = import->location;
scriptRef.qualifier = importQualifier;
scriptRef.compilation = NULL;
d->compilation->scripts.append(scriptRef);
} else if (import->type == QV4::CompiledData::Import::ImportLibrary) {
QString qmldirFilePath;
QString qmldirUrl;
if (QQmlMetaType::isLockedModule(importUri, import->majorVersion)) {
//Locked modules are checked first, to save on filesystem checks
if (!d->compilation->importCache->addLibraryImport(d->compilation->importDatabase, importUri, importQualifier, import->majorVersion,
import->minorVersion, QString(), QString(), false, errors))
return false;
} else if (d->compilation->importCache->locateQmldir(d->compilation->importDatabase, importUri, import->majorVersion, import->minorVersion,
&qmldirFilePath, &qmldirUrl)) {
// This is a local library import
if (!d->compilation->importCache->addLibraryImport(d->compilation->importDatabase, importUri, importQualifier, import->majorVersion,
import->minorVersion, qmldirFilePath, qmldirUrl, false, errors))
return false;
if (!importQualifier.isEmpty()) {
// Does this library contain any qualified scripts?
QUrl libraryUrl(qmldirUrl);
QQmlTypeLoader* typeLoader = &QQmlEnginePrivate::get(d->compilation->engine)->typeLoader;
const QQmlTypeLoader::QmldirContent *qmldir = typeLoader->qmldirContent(qmldirFilePath, qmldirUrl);
foreach (const QQmlDirParser::Script &script, qmldir->scripts()) {
// TBD: qqmltypeloader.cpp:1343
qDebug() << "Library contains scripts";
QQmlError error;
error.setDescription("Libraries with scripts not supported");
appendError(error);
return false;
}
}
} else {
示例12: Q_D
bool Compiler::compile(const QString &url)
{
Q_D(Compiler);
clearError();
// set env var so one can test in plugins if needed
setenv("QMC_COMPILE", "1", 1);
// check that engine is using correct factory
if (!qgetenv("QV4_FORCE_INTERPRETER").isEmpty()) {
QQmlError error;
error.setDescription("Compiler is forced to use interpreter");
appendError(error);
return false;
}
Q_ASSERT(d->compilation == NULL);
QmlCompilation* c = new QmlCompilation(url, QUrl(url), d->engine);
d->compilation = c;
c->importCache = new QQmlImports(&QQmlEnginePrivate::get(d->compilation->engine)->typeLoader);
c->importDatabase = new QQmlImportDatabase(d->compilation->engine);
c->loadUrl = url;
int lastSlash = url.lastIndexOf('/');
if (lastSlash == -1)
c->url = url;
else if (lastSlash + 1 < url.length())
c->url = url.mid(lastSlash + 1);
else
c->url = "";
if (!loadData()) {
delete takeCompilation();
return false;
}
if (!compileData()) {
delete takeCompilation();
return false;
}
return true;
}
示例13: exceptionToError
void QQmlJavaScriptExpression::exceptionToError(v8::Handle<v8::Message> message, QQmlError &error)
{
Q_ASSERT(!message.IsEmpty());
v8::Handle<v8::Value> name = message->GetScriptResourceName();
v8::Handle<v8::String> description = message->Get();
int lineNumber = message->GetLineNumber();
v8::Local<v8::String> file = name->IsString()?name->ToString():v8::Local<v8::String>();
if (file.IsEmpty() || file->Length() == 0)
error.setUrl(QUrl());
else
error.setUrl(QUrl(QV8Engine::toStringStatic(file)));
error.setLine(lineNumber);
error.setColumn(-1);
QString qDescription = QV8Engine::toStringStatic(description);
if (qDescription.startsWith(QLatin1String("Uncaught ")))
qDescription = qDescription.mid(9 /* strlen("Uncaught ") */);
error.setDescription(qDescription);
}
示例14: ctxtscope
// Callee owns the persistent handle
v8::Persistent<v8::Function>
QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
const char *code, int codeLength,
const QString &filename, quint16 line,
v8::Persistent<v8::Object> *qmlscope)
{
QQmlEngine *engine = ctxt->engine;
QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
v8::HandleScope handle_scope;
v8::Context::Scope ctxtscope(ep->v8engine()->context());
v8::TryCatch tc;
v8::Local<v8::Object> scopeobject = ep->v8engine()->qmlScope(ctxt, scope);
v8::Local<v8::Script> script = ep->v8engine()->qmlModeCompile(code, codeLength, filename, line);
if (tc.HasCaught()) {
QQmlError error;
error.setDescription(QLatin1String("Exception occurred during function compilation"));
error.setLine(line);
error.setUrl(QUrl::fromLocalFile(filename));
v8::Local<v8::Message> message = tc.Message();
if (!message.IsEmpty())
QQmlExpressionPrivate::exceptionToError(message, error);
ep->warning(error);
return v8::Persistent<v8::Function>();
}
v8::Local<v8::Value> result = script->Run(scopeobject);
if (tc.HasCaught()) {
QQmlError error;
error.setDescription(QLatin1String("Exception occurred during function evaluation"));
error.setLine(line);
error.setUrl(QUrl::fromLocalFile(filename));
v8::Local<v8::Message> message = tc.Message();
if (!message.IsEmpty())
QQmlExpressionPrivate::exceptionToError(message, error);
ep->warning(error);
return v8::Persistent<v8::Function>();
}
if (qmlscope) *qmlscope = qPersistentNew<v8::Object>(scopeobject);
return qPersistentNew<v8::Function>(v8::Local<v8::Function>::Cast(result));
}
示例15: f
QDebug operator<<(QDebug debug, const QQmlError &error)
{
debug << qPrintable(error.toString());
QUrl url = error.url();
if (error.line() > 0 && url.scheme() == QLatin1String("file")) {
QString file = url.toLocalFile();
QFile f(file);
if (f.open(QIODevice::ReadOnly)) {
QByteArray data = f.readAll();
QTextStream stream(data, QIODevice::ReadOnly);
#ifndef QT_NO_TEXTCODEC
stream.setCodec("UTF-8");
#endif
const QString code = stream.readAll();
const QStringList lines = code.split(QLatin1Char('\n'));
if (lines.count() >= error.line()) {
const QString &line = lines.at(error.line() - 1);
debug << "\n " << qPrintable(line);
if(error.column() > 0) {
int column = qMax(0, error.column() - 1);
column = qMin(column, line.length());
QByteArray ind;
ind.reserve(column);
for (int i = 0; i < column; ++i) {
const QChar ch = line.at(i);
if (ch.isSpace())
ind.append(ch.unicode());
else
ind.append(' ');
}
ind.append('^');
debug << "\n " << ind.constData();
}
}
}
}
return debug;
}