##// END OF EJS Templates
Demo launcher now works on OSX
Tero Ahola -
r2237:adf2813ece47
parent child
Show More
@@ -4,5 +4,3 TARGET = demoLauncher
4 4 SOURCES += main.cpp\
5 5 widget.cpp
6 6 HEADERS += widget.h
7
8 DEFINES += "BINPATH=$$join($$CHART_BUILD_BIN_DIR, ", ")"
@@ -4,26 +4,36
4 4 #include <QGridLayout>
5 5 #include <QApplication>
6 6 #include <QProcess>
7 #include <QDebug>
7 8
8 9 Widget::Widget(QWidget *parent)
9 10 : QWidget(parent),
10 11 m_demoApp(0)
11 12 {
13 // Create a list of executables
12 14 QList<QFileInfo> appList;
13 QDir appFolder = QDir(BINPATH);
14 appList = appFolder.entryInfoList(QDir::Files);
15
15 m_appFolder = QDir(QApplication::applicationDirPath());
16 #ifdef Q_WS_MAC
17 // The executable is inside an application bundle (a folder) on OSX
18 m_appFolder.cdUp();
19 m_appFolder.cdUp();
20 m_appFolder.cdUp();
21 appList = m_appFolder.entryInfoList(QStringList("*.app"), QDir::Executable | QDir::Dirs | QDir::NoDotAndDotDot);
22 #elif Q_WS_WIN
23 appList = m_appFolder.entryInfoList(QStringList("*.exe"), QDir::Executable | QDir::Files | QDir::NoDotAndDotDot);
24 #else
25 appList = m_appFolder.entryInfoList(QDir::Executable | QDir::Files | QDir::NoDotAndDotDot);
26 #endif
16 27 for (int k = appList.count() - 1; k >= 0; k--) {
17 28 QString name = appList[k].fileName();
18 if (name.startsWith("tst_")
19 || name.startsWith("demoLauncher")
20 || (name.right(4).left(1) == "." && !name.endsWith("exe")))
29 if (name.startsWith("tst_") || name.startsWith("demoLauncher"))
21 30 appList.removeAt(k);
22 31 }
23 32
33 // Create push buttons for starting the executables
24 34 QGridLayout* demosLayout = new QGridLayout;
25 35 for( int i = 0; i < appList.count(); i++) {
26 QPushButton *button = new QPushButton(appList[i].baseName());
36 QPushButton *button = new QPushButton(appList[i].fileName());
27 37 connect(button, SIGNAL(clicked()), this, SLOT (runApp()));
28 38 demosLayout->addWidget(button, i%10, i/10);
29 39 }
@@ -39,8 +49,7 Widget::~Widget()
39 49 void Widget::runApp()
40 50 {
41 51 QString name = qobject_cast<QPushButton *>(sender())->text();
42 QString program = QDir(BINPATH).absolutePath() + QDir::separator() + name;
43
52 QString program = m_appFolder.absolutePath() + QDir::separator() + name;
44 53 m_demoApp = new QProcess(this);
45 54 m_demoApp->start(program);
46 55 }
@@ -2,6 +2,7
2 2 #define WIDGET_H
3 3
4 4 #include <QWidget>
5 #include <QDir>
5 6
6 7 class QProcess;
7 8
@@ -17,6 +18,7 public slots:
17 18 void runApp();
18 19
19 20 private:
21 QDir m_appFolder;
20 22 QProcess *m_demoApp;
21 23 };
22 24
General Comments 0
You need to be logged in to leave comments. Login now