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