##// END OF EJS Templates
Qt5 build fixes
Qt5 build fixes

File last commit:

r2239:7132c010391a
r2239:7132c010391a
Show More
widget.cpp
55 lines | 1.7 KiB | text/x-c | CppLexer
Marek Rosa
Added simple demoLauncher application
r2229 #include "widget.h"
#include <QPushButton>
#include <QDir>
#include <QGridLayout>
#include <QApplication>
#include <QProcess>
Tero Ahola
Demo launcher now works on OSX
r2237 #include <QDebug>
Marek Rosa
Added simple demoLauncher application
r2229
Widget::Widget(QWidget *parent)
: QWidget(parent),
m_demoApp(0)
{
Tero Ahola
Demo launcher now works on OSX
r2237 // Create a list of executables
Marek Rosa
Added simple demoLauncher application
r2229 QList<QFileInfo> appList;
Tero Ahola
Demo launcher now works on OSX
r2237 m_appFolder = QDir(QApplication::applicationDirPath());
Tero Ahola
Qt5 build fixes
r2239 #ifdef Q_OS_MAC
Tero Ahola
Demo launcher now works on OSX
r2237 // The executable is inside an application bundle (a folder) on OSX
m_appFolder.cdUp();
m_appFolder.cdUp();
m_appFolder.cdUp();
appList = m_appFolder.entryInfoList(QStringList("*.app"), QDir::Executable | QDir::Dirs | QDir::NoDotAndDotDot);
Tero Ahola
Qt5 build fixes
r2239 #elif defined(Q_OS_WIN)
Tero Ahola
Demo launcher now works on OSX
r2237 appList = m_appFolder.entryInfoList(QStringList("*.exe"), QDir::Executable | QDir::Files | QDir::NoDotAndDotDot);
#else
appList = m_appFolder.entryInfoList(QDir::Executable | QDir::Files | QDir::NoDotAndDotDot);
#endif
Marek Rosa
demolauncher fix
r2232 for (int k = appList.count() - 1; k >= 0; k--) {
QString name = appList[k].fileName();
Tero Ahola
Demo launcher now works on OSX
r2237 if (name.startsWith("tst_") || name.startsWith("demoLauncher"))
Marek Rosa
demolauncher fix
r2232 appList.removeAt(k);
}
Tero Ahola
Demo launcher now works on OSX
r2237 // Create push buttons for starting the executables
Marek Rosa
Added simple demoLauncher application
r2229 QGridLayout* demosLayout = new QGridLayout;
for( int i = 0; i < appList.count(); i++) {
Tero Ahola
Demo launcher now works on OSX
r2237 QPushButton *button = new QPushButton(appList[i].fileName());
Marek Rosa
Added simple demoLauncher application
r2229 connect(button, SIGNAL(clicked()), this, SLOT (runApp()));
demosLayout->addWidget(button, i%10, i/10);
}
setLayout(demosLayout);
}
Widget::~Widget()
{
Marek Rosa
demolauncher fix
r2232 if (m_demoApp)
m_demoApp->close();
Marek Rosa
Added simple demoLauncher application
r2229 }
void Widget::runApp()
{
QString name = qobject_cast<QPushButton *>(sender())->text();
Tero Ahola
Demo launcher now works on OSX
r2237 QString program = m_appFolder.absolutePath() + QDir::separator() + name;
Marek Rosa
Added simple demoLauncher application
r2229 m_demoApp = new QProcess(this);
m_demoApp->start(program);
}