@@ -1,8 +1,6 | |||||
1 | !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" ) |
|
1 | !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" ) | |
2 |
|
2 | |||
3 | TARGET = demoLauncher |
|
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, ", ")" |
|
@@ -1,46 +1,55 | |||||
1 | #include "widget.h" |
|
1 | #include "widget.h" | |
2 | #include <QPushButton> |
|
2 | #include <QPushButton> | |
3 | #include <QDir> |
|
3 | #include <QDir> | |
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 | } | |
30 | setLayout(demosLayout); |
|
40 | setLayout(demosLayout); | |
31 | } |
|
41 | } | |
32 |
|
42 | |||
33 | Widget::~Widget() |
|
43 | Widget::~Widget() | |
34 | { |
|
44 | { | |
35 | if (m_demoApp) |
|
45 | if (m_demoApp) | |
36 | m_demoApp->close(); |
|
46 | m_demoApp->close(); | |
37 | } |
|
47 | } | |
38 |
|
48 | |||
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 | } |
@@ -1,23 +1,25 | |||||
1 | #ifndef WIDGET_H |
|
1 | #ifndef WIDGET_H | |
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 | |||
8 | class Widget : public QWidget |
|
9 | class Widget : public QWidget | |
9 | { |
|
10 | { | |
10 | Q_OBJECT |
|
11 | Q_OBJECT | |
11 |
|
12 | |||
12 | public: |
|
13 | public: | |
13 | Widget(QWidget *parent = 0); |
|
14 | Widget(QWidget *parent = 0); | |
14 | ~Widget(); |
|
15 | ~Widget(); | |
15 |
|
16 | |||
16 | public slots: |
|
17 | 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 | |||
23 | #endif // WIDGET_H |
|
25 | #endif // WIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now