widget.cpp
46 lines
| 1.2 KiB
| text/x-c
|
CppLexer
|
r2229 | #include "widget.h" | ||
#include <QPushButton> | ||||
#include <QDir> | ||||
#include <QGridLayout> | ||||
#include <QApplication> | ||||
#include <QProcess> | ||||
#include <QTimer> | ||||
Widget::Widget(QWidget *parent) | ||||
: QWidget(parent), | ||||
m_demoApp(0) | ||||
{ | ||||
QList<QFileInfo> appList; | ||||
QDir appFolder(QApplication::applicationDirPath()); | ||||
appList = appFolder.entryInfoList(QDir::Files); | ||||
|
r2232 | for (int k = appList.count() - 1; k >= 0; k--) { | ||
QString name = appList[k].fileName(); | ||||
if (name.endsWith("exp") || name.endsWith("dll") || name.endsWith("lib") || name.startsWith("tst_")) | ||||
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); | ||||
} | ||||