qml tool on OSX: wait for a timeout before exiting

Double-clicking to open a QML file was not working because it would
exit if no files are given on the command line.  It needs to wait
a while for the QFileOpenEvent.

Task-number: QTBUG-34926
Change-Id: Icb585a777b0438db85120c62e7717f0f6eafffb1
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
Shawn Rutledge 2013-11-18 15:57:08 +01:00 committed by The Qt Project
parent 3f1245aabc
commit 61cf2b0633
1 changed files with 28 additions and 4 deletions

View File

@ -72,8 +72,11 @@
#define VERSION_MIN 0
#define VERSION_STR "1.0"
#define FILE_OPEN_EVENT_WAIT_TIME 3000 // ms
static Config *conf = 0;
static QQmlApplicationEngine *qae = 0;
static int exitTimerId = -1;
static void loadConf(const QString &override, bool quiet) // Terminates app on failure
{
@ -138,6 +141,8 @@ void contain(QObject *o, const QUrl &containPath)
#ifdef QT_GUI_LIB
void noFilesGiven();
// Loads qml after receiving a QFileOpenEvent
class LoaderApplication : public QGuiApplication
{
@ -146,12 +151,21 @@ public:
bool event(QEvent *ev)
{
if (ev->type() == QEvent::FileOpen)
if (ev->type() == QEvent::FileOpen) {
if (exitTimerId >= 0) {
killTimer(exitTimerId);
exitTimerId = -1;
}
qae->load(static_cast<QFileOpenEvent *>(ev)->url());
}
else
return QGuiApplication::event(ev);
return true;
}
void timerEvent(QTimerEvent *) {
noFilesGiven();
}
};
#endif // QT_GUI_LIB
@ -274,6 +288,13 @@ void printUsage()
exit(0);
}
void noFilesGiven()
{
if (!quietMode)
printf("qml: No files specified. Terminating.\n");
exit(1);
}
//Called before application initialization, removes arguments it uses
void getAppFlags(int &argc, char **argv)
{
@ -462,9 +483,12 @@ int main(int argc, char *argv[])
qInstallMessageHandler(quietMessageHandler);
if (files.count() <= 0) {
if (!quietMode)
printf("qml: No files specified. Terminating.\n");
exit(1);
#if defined(Q_OS_MAC)
if (applicationType == QmlApplicationTypeGui)
exitTimerId = static_cast<LoaderApplication *>(app)->startTimer(FILE_OPEN_EVENT_WAIT_TIME);
else
#endif
noFilesGiven();
}
qae = &e;