forked from qt-creator/qt-creator
QmlDesigner: Show proper error message for component
If a component cannot be created we have to show a proper error message. Task-number: QDS-1980 Change-Id: I48a6ff0fd89c9666328c501abb00dc0997171d96 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -199,6 +199,18 @@ Internal::ObjectNodeInstance::Pointer ServerNodeInstance::createInstance(QObject
|
||||
return instance;
|
||||
}
|
||||
|
||||
QString static getErrorString(QQmlEngine *engine, const QString &componentPath)
|
||||
{
|
||||
QQmlComponent component(engine, componentPath);
|
||||
|
||||
QObject *o = component.create(nullptr);
|
||||
delete o;
|
||||
QString s;
|
||||
for (const QQmlError &error : component.errors())
|
||||
s.append(error.toString());
|
||||
return s;
|
||||
}
|
||||
|
||||
ServerNodeInstance ServerNodeInstance::create(NodeInstanceServer *nodeInstanceServer,
|
||||
const InstanceContainer &instanceContainer,
|
||||
ComponentWrap componentWrap)
|
||||
@@ -215,8 +227,11 @@ ServerNodeInstance ServerNodeInstance::create(NodeInstanceServer *nodeInstanceSe
|
||||
nodeInstanceServer->sendDebugOutput(DebugOutputCommand::ErrorType, QLatin1String("Custom parser object could not be created."), instanceContainer.instanceId());
|
||||
} else if (!instanceContainer.componentPath().isEmpty()) {
|
||||
object = Internal::ObjectNodeInstance::createComponent(instanceContainer.componentPath(), nodeInstanceServer->context());
|
||||
if (object == nullptr)
|
||||
nodeInstanceServer->sendDebugOutput(DebugOutputCommand::ErrorType, QString("Component with path %1 could not be created.").arg(instanceContainer.componentPath()), instanceContainer.instanceId());
|
||||
if (object == nullptr) {
|
||||
const QString errors = getErrorString(nodeInstanceServer->engine(), instanceContainer.componentPath());
|
||||
const QString message = QString("Component with path %1 could not be created.\n\n").arg(instanceContainer.componentPath());
|
||||
nodeInstanceServer->sendDebugOutput(DebugOutputCommand::ErrorType, message + errors, instanceContainer.instanceId());
|
||||
}
|
||||
} else {
|
||||
object = Internal::ObjectNodeInstance::createPrimitive(QString::fromUtf8(instanceContainer.type()), instanceContainer.majorNumber(), instanceContainer.minorNumber(), nodeInstanceServer->context());
|
||||
if (object == nullptr)
|
||||
|
||||
Reference in New Issue
Block a user