diff --git a/demos/demoLauncher/demoLauncher.pro b/demos/demoLauncher/demoLauncher.pro index 01ba226..f723d12 100644 --- a/demos/demoLauncher/demoLauncher.pro +++ b/demos/demoLauncher/demoLauncher.pro @@ -4,5 +4,3 @@ TARGET = demoLauncher SOURCES += main.cpp\ widget.cpp HEADERS += widget.h - -DEFINES += "BINPATH=$$join($$CHART_BUILD_BIN_DIR, ", ")" diff --git a/demos/demoLauncher/widget.cpp b/demos/demoLauncher/widget.cpp index f449e8b..ea30448 100644 --- a/demos/demoLauncher/widget.cpp +++ b/demos/demoLauncher/widget.cpp @@ -4,26 +4,36 @@ #include #include #include +#include Widget::Widget(QWidget *parent) : QWidget(parent), m_demoApp(0) { + // Create a list of executables QList appList; - QDir appFolder = QDir(BINPATH); - appList = appFolder.entryInfoList(QDir::Files); - + m_appFolder = QDir(QApplication::applicationDirPath()); +#ifdef Q_WS_MAC + // The executable is inside an application bundle (a folder) on OSX + m_appFolder.cdUp(); + m_appFolder.cdUp(); + m_appFolder.cdUp(); + appList = m_appFolder.entryInfoList(QStringList("*.app"), QDir::Executable | QDir::Dirs | QDir::NoDotAndDotDot); +#elif Q_WS_WIN + appList = m_appFolder.entryInfoList(QStringList("*.exe"), QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); +#else + appList = m_appFolder.entryInfoList(QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); +#endif for (int k = appList.count() - 1; k >= 0; k--) { QString name = appList[k].fileName(); - if (name.startsWith("tst_") - || name.startsWith("demoLauncher") - || (name.right(4).left(1) == "." && !name.endsWith("exe"))) + if (name.startsWith("tst_") || name.startsWith("demoLauncher")) appList.removeAt(k); } + // Create push buttons for starting the executables QGridLayout* demosLayout = new QGridLayout; for( int i = 0; i < appList.count(); i++) { - QPushButton *button = new QPushButton(appList[i].baseName()); + QPushButton *button = new QPushButton(appList[i].fileName()); connect(button, SIGNAL(clicked()), this, SLOT (runApp())); demosLayout->addWidget(button, i%10, i/10); } @@ -39,8 +49,7 @@ Widget::~Widget() void Widget::runApp() { QString name = qobject_cast(sender())->text(); - QString program = QDir(BINPATH).absolutePath() + QDir::separator() + name; - + QString program = m_appFolder.absolutePath() + QDir::separator() + name; m_demoApp = new QProcess(this); m_demoApp->start(program); } diff --git a/demos/demoLauncher/widget.h b/demos/demoLauncher/widget.h index 863b7df..8946724 100644 --- a/demos/demoLauncher/widget.h +++ b/demos/demoLauncher/widget.h @@ -2,6 +2,7 @@ #define WIDGET_H #include +#include class QProcess; @@ -17,6 +18,7 @@ public slots: void runApp(); private: + QDir m_appFolder; QProcess *m_demoApp; };