widget.cpp
48 lines
| 1.3 KiB
| text/x-c
|
CppLexer
|
r2229 | #include "widget.h" | ||
#include <QPushButton> | ||||
#include <QDir> | ||||
#include <QGridLayout> | ||||
#include <QApplication> | ||||
#include <QProcess> | ||||
Widget::Widget(QWidget *parent) | ||||
: QWidget(parent), | ||||
m_demoApp(0) | ||||
{ | ||||
QList<QFileInfo> appList; | ||||
|
r2234 | QDir appFolder = QDir(BINPATH); | ||
|
r2229 | appList = appFolder.entryInfoList(QDir::Files); | ||
|
r2232 | for (int k = appList.count() - 1; k >= 0; k--) { | ||
QString name = appList[k].fileName(); | ||||
|
r2234 | if (name.endsWith("exp") | ||
|| name.endsWith("dll") | ||||
|| name.endsWith("lib") | ||||
|| name.startsWith("tst_") | ||||
|| name.startsWith("demoLauncher")) | ||||
|
r2232 | appList.removeAt(k); | ||
} | ||||
|
r2229 | QGridLayout* demosLayout = new QGridLayout; | ||
for( int i = 0; i < appList.count(); i++) { | ||||
QPushButton *button = new QPushButton(appList[i].fileName()); | ||||
connect(button, SIGNAL(clicked()), this, SLOT (runApp())); | ||||
demosLayout->addWidget(button, i%10, i/10); | ||||
} | ||||
setLayout(demosLayout); | ||||
} | ||||
Widget::~Widget() | ||||
{ | ||||
|
r2232 | if (m_demoApp) | ||
m_demoApp->close(); | ||||
|
r2229 | } | ||
void Widget::runApp() | ||||
{ | ||||
QString name = qobject_cast<QPushButton *>(sender())->text(); | ||||
QString program = QApplication::applicationDirPath() + QDir::separator() + name; | ||||
m_demoApp = new QProcess(this); | ||||
m_demoApp->start(program); | ||||
} | ||||