ZikO
1st September 2012, 14:40
Hi,
I am currently making an application that will residue in a system tray and show a message per hour. Before all these can work, I will need to perform some tests to make sure there are required files. The application needs to be terminated immediately if something is missing. First, I simply tried to use QApplication::quit() or qApp->quit(). However, it cannot work if Event Loop is executed in a program via return app.exec()--this is usually the last command in my programs. I've thought that I might not always need to execute the Event Loop and the application can be terminated at once. Though, I don't know if this is a correct approach and would be grateful if someone could provide a better way of solving this problem.
Thanks
Below is this the test program.
#include <QApplication>
#include <QFile>
#include <QMessageBox>
#include <QIcon>
//#include "stworz_plik/rekord.h"
//#include "stworz_plik/errors.h"
namespace Wydarzenia {
enum code {NOERROR, ERRORFILE};
const QString CFILENAME = "database";
}
bool testFile(const QString& fileName, Wydarzenia::code& locStatus) {
using namespace Wydarzenia;
QFile dbFile(fileName);
if(dbFile.open(QIODevice::ReadOnly)) {
locStatus = NOERROR;
return true;
} else {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText(QObject::trUtf8("Cannot find the file %L1").arg(fileName));
msgBox.setInformativeText(QObject::trUtf8("The file %L1 is required and must be in the same folder as the application").arg(fileName));
msgBox.setStandardButtons(QMessageBox::Close);
msgBox.setDefaultButton(QMessageBox::Close);
msgBox.exec();
locStatus = ERRORFILE;
return false;
}
}
int main(int argc, char* argv[]) {
using namespace Wydarzenia;
QApplication app(argc,argv);
code status;
if(testFile(CFILENAME,status)) {
// Main program where I am going to create:
// * a Window object
// * a QSystemTrayIcon
// ...
return app.exec();
} else
return EXIT_FAILURE;
}
I am currently making an application that will residue in a system tray and show a message per hour. Before all these can work, I will need to perform some tests to make sure there are required files. The application needs to be terminated immediately if something is missing. First, I simply tried to use QApplication::quit() or qApp->quit(). However, it cannot work if Event Loop is executed in a program via return app.exec()--this is usually the last command in my programs. I've thought that I might not always need to execute the Event Loop and the application can be terminated at once. Though, I don't know if this is a correct approach and would be grateful if someone could provide a better way of solving this problem.
Thanks
Below is this the test program.
#include <QApplication>
#include <QFile>
#include <QMessageBox>
#include <QIcon>
//#include "stworz_plik/rekord.h"
//#include "stworz_plik/errors.h"
namespace Wydarzenia {
enum code {NOERROR, ERRORFILE};
const QString CFILENAME = "database";
}
bool testFile(const QString& fileName, Wydarzenia::code& locStatus) {
using namespace Wydarzenia;
QFile dbFile(fileName);
if(dbFile.open(QIODevice::ReadOnly)) {
locStatus = NOERROR;
return true;
} else {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText(QObject::trUtf8("Cannot find the file %L1").arg(fileName));
msgBox.setInformativeText(QObject::trUtf8("The file %L1 is required and must be in the same folder as the application").arg(fileName));
msgBox.setStandardButtons(QMessageBox::Close);
msgBox.setDefaultButton(QMessageBox::Close);
msgBox.exec();
locStatus = ERRORFILE;
return false;
}
}
int main(int argc, char* argv[]) {
using namespace Wydarzenia;
QApplication app(argc,argv);
code status;
if(testFile(CFILENAME,status)) {
// Main program where I am going to create:
// * a Window object
// * a QSystemTrayIcon
// ...
return app.exec();
} else
return EXIT_FAILURE;
}