aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@digia.com>2012-10-02 11:45:13 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-04 08:17:33 +0200
commite20dae13601e01321ea8fd34309d6ecb3212d92b (patch)
tree896cb1f6df48659b8e1fedb79f026c67488b0658
parenta81655579c6799671a289b20f44a9d36e7584064 (diff)
Use correct path to qml files when looking for them in examples
As executables might end up in different folders on different plaforms when built, examples' shared.h should not rely on having the qml files in the same folder as the executables. On Windows they end up in debug/ release by default, while they are put in foo.app/Contents/MacOs on Mac if app_bundle is set in CONFIG. Change-Id: If0cea4c186920eb4689d5941b6ff5f333d97c574 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com> Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
-rw-r--r--examples/shared/shared.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/examples/shared/shared.h b/examples/shared/shared.h
index 2a6cce0bd4..613798f078 100644
--- a/examples/shared/shared.h
+++ b/examples/shared/shared.h
@@ -37,13 +37,30 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QDir>
#include <QGuiApplication>
#include <QQuickView>
#define DECLARATIVE_EXAMPLE_MAIN(NAME) int main(int argc, char* argv[]) \
{\
QGuiApplication app(argc,argv);\
QQuickView view;\
- view.setSource(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + QLatin1String("/" #NAME ".qml")));\
+ QDir directory(QCoreApplication::applicationDirPath());\
+ if (QGuiApplication::platformName() == QLatin1String("windows")) {\
+ if (directory.absolutePath().endsWith("/debug", Qt::CaseInsensitive)\
+ || directory.absolutePath().endsWith("/release", Qt::CaseInsensitive))\
+ if (!directory.cdUp())\
+ exit(-1);\
+ } else if (QGuiApplication::platformName() == QLatin1String("Cocoa")) {\
+ if (directory.absolutePath().endsWith(#NAME".app/Contents/MacOS"))\
+ for (int i = 0; i < 3; ++i) {\
+ if (!directory.cdUp())\
+ exit(-1);\
+ }\
+ }\
+ const QString fileName(directory.absolutePath() + "/" #NAME ".qml");\
+ if (!QFile::exists(fileName))\
+ exit(-1);\
+ view.setSource(QUrl::fromLocalFile(fileName));\
view.show();\
return app.exec();\
}