From 0beb721fc882741f2b5e42dfae5cab09d4c6b2a8 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 14 Jun 2011 12:26:08 +0200 Subject: QmlDesigner.nodeInstances: fix for incompatible Qt Version If the Qt Version is incomaptible (e. g. mingw) we have to use the qml file for a component shipped with Creator. Otherwise a import "." statement will break the component. Change-Id: I7e354a15205567407533579f92e65f2be73a614ex Reviewed-on: http://codereview.qt.nokia.com/474 Reviewed-by: Qt Sanity Bot Reviewed-by: hjk --- .../designercore/instances/objectnodeinstance.cpp | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp index f36261027b0..6f1e9098be6 100644 --- a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp @@ -60,6 +60,7 @@ #include #include +#include #include #include @@ -736,10 +737,31 @@ void tweakObjects(QObject *object) } +//The component might also be shipped with Creator. +//To avoid trouble with import "." we use the component shipped with Creator. +static inline QString fixComponentPathForIncompatibleQt(const QString &componentPath) +{ + QString result = componentPath; + const QLatin1String importString("import"); + + if (componentPath.contains(importString)) { + int index = componentPath.indexOf(importString) + 7; + const QString relativeImportPath = componentPath.right(componentPath.length() - index); + QString fixedComponentPath = QLibraryInfo::location(QLibraryInfo::ImportsPath) + relativeImportPath; + fixedComponentPath.replace(QLatin1Char('\\'), QLatin1Char('/')); + if (QFileInfo(fixedComponentPath).exists()) + return fixedComponentPath; + } + + return result; + +} + QObject *createComponent(const QString &componentPath, QDeclarativeContext *context) { - QDeclarativeComponent component(context->engine(), QUrl::fromLocalFile(componentPath)); + QDeclarativeComponent component(context->engine(), QUrl::fromLocalFile(fixComponentPathForIncompatibleQt(componentPath))); QObject *object = component.beginCreate(context); + tweakObjects(object); component.completeCreate(); -- cgit v1.2.3