本文整理汇总了C++中QQmlError::setDescription方法的典型用法代码示例。如果您正苦于以下问题:C++ QQmlError::setDescription方法的具体用法?C++ QQmlError::setDescription怎么用?C++ QQmlError::setDescription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQmlError
的用法示例。
在下文中一共展示了QQmlError::setDescription方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copy
void tst_qqmlerror::copy()
{
QQmlError error;
error.setUrl(QUrl("http://www.qt-project.org/main.qml"));
error.setDescription("An Error");
error.setLine(92);
error.setColumn(13);
QQmlError error2(error);
QQmlError error3;
error3 = error;
error.setUrl(QUrl("http://www.qt-project.org/main.qml"));
error.setDescription("Another Error");
error.setLine(2);
error.setColumn(33);
QCOMPARE(error.url(), QUrl("http://www.qt-project.org/main.qml"));
QCOMPARE(error.description(), QString("Another Error"));
QCOMPARE(error.line(), 2);
QCOMPARE(error.column(), 33);
QCOMPARE(error2.url(), QUrl("http://www.qt-project.org/main.qml"));
QCOMPARE(error2.description(), QString("An Error"));
QCOMPARE(error2.line(), 92);
QCOMPARE(error2.column(), 13);
QCOMPARE(error3.url(), QUrl("http://www.qt-project.org/main.qml"));
QCOMPARE(error3.description(), QString("An Error"));
QCOMPARE(error3.line(), 92);
QCOMPARE(error3.column(), 13);
}
示例2: qmlBinding
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();
}
示例3: 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;
}
示例4: lexer
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();
}
示例5: 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);
}
示例6: setWindowVisibility
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);
}
}
示例7: description
void tst_qqmlerror::description()
{
QQmlError error;
QCOMPARE(error.description(), QString());
error.setDescription("An Error");
QCOMPARE(error.description(), QString("An Error"));
QQmlError error2 = error;
QCOMPARE(error2.description(), QString("An Error"));
error.setDescription("Another Error");
QCOMPARE(error.description(), QString("Another Error"));
QCOMPARE(error2.description(), QString("An Error"));
}
示例8: exportData
bool Compiler::exportData(QDataStream &output)
{
Q_D(Compiler);
if (!d->compilation->checkData()) {
QQmlError error;
error.setDescription("Compiled data not valid. Internal error.");
appendError(error);
return false;
}
QmcExporter exporter(d->compilation);
bool ret = exporter.exportQmc(output);
if (!ret) {
QQmlError error;
error.setDescription("Error saving data");
appendError(error);
}
return ret;
}
示例9: 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));
}
示例10: debug
void tst_qqmlerror::debug()
{
{
QQmlError error;
error.setUrl(QUrl("http://www.qt-project.org/main.qml"));
error.setDescription("An Error");
error.setLine(92);
error.setColumn(13);
QTest::ignoreMessage(QtWarningMsg, "http://www.qt-project.org/main.qml:92:13: An Error ");
qWarning() << error;
}
{
QUrl url(dataDirectoryUrl().resolved(QUrl("test.txt")));
QQmlError error;
error.setUrl(url);
error.setDescription("An Error");
error.setLine(2);
error.setColumn(5);
QString out = url.toString() + ":2:5: An Error \n Line2 Content \n ^ ";
QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
qWarning() << error;
}
{
QUrl url(dataDirectoryUrl().resolved(QUrl("foo.txt")));
QQmlError error;
error.setUrl(url);
error.setDescription("An Error");
error.setLine(2);
error.setColumn(5);
QString out = url.toString() + ":2:5: An Error ";
QTest::ignoreMessage(QtWarningMsg, qPrintable(out));
qWarning() << error;
}
}
示例11: toString
void tst_qqmlerror::toString()
{
{
QQmlError error;
error.setUrl(QUrl("http://www.qt-project.org/main.qml"));
error.setDescription("An Error");
error.setLine(92);
error.setColumn(13);
QCOMPARE(error.toString(), QString("http://www.qt-project.org/main.qml:92:13: An Error"));
}
{
QQmlError error;
error.setUrl(QUrl("http://www.qt-project.org/main.qml"));
error.setDescription("An Error");
error.setLine(92);
QCOMPARE(error.toString(), QString("http://www.qt-project.org/main.qml:92: An Error"));
}
}
示例12: compile
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;
}
示例13: 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;
}
示例14: addImport
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 {
示例15: compile
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;
}