summaryrefslogtreecommitdiffstats
path: root/tools/qml/main.cpp
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2010-04-21 07:14:07 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2010-04-21 07:14:07 (GMT)
commitd420eb68b9a306f0fccf3000a8af31aa00cb0cd9 (patch)
tree44c958741cd0189acd5ac875d57d28165f051aae /tools/qml/main.cpp
parent202af3021362d3c8066bc479a95e7aad889bd928 (diff)
parentb72f9dacb352aa4be888c5f7f1a482dbcba1f456 (diff)
downloadQt-d420eb68b9a306f0fccf3000a8af31aa00cb0cd9.zip
Qt-d420eb68b9a306f0fccf3000a8af31aa00cb0cd9.tar.gz
Qt-d420eb68b9a306f0fccf3000a8af31aa00cb0cd9.tar.bz2
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'tools/qml/main.cpp')
-rw-r--r--tools/qml/main.cpp118
1 files changed, 87 insertions, 31 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index 5e829a4..cba5650 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -42,16 +42,20 @@
#include "qdeclarative.h"
#include "qmlruntime.h"
#include "qdeclarativeengine.h"
+#include "loggerwidget.h"
#include <QWidget>
#include <QDir>
#include <QApplication>
#include <QTranslator>
#include <QDebug>
+#include <QMessageBox>
#include "qdeclarativetester.h"
#include "qdeclarativefolderlistmodel.h"
QT_USE_NAMESPACE
+QtMsgHandler systemMsgOutput;
+
#if defined (Q_OS_SYMBIAN)
#include <unistd.h>
#include <sys/types.h>
@@ -73,6 +77,36 @@ void myMessageOutput(QtMsgType type, const char *msg)
abort();
}
}
+
+#else // !defined (Q_OS_SYMBIAN)
+
+QWeakPointer<LoggerWidget> logger;
+
+QString warnings;
+void showWarnings()
+{
+ if (!warnings.isEmpty()) {
+ QMessageBox::warning(0, QApplication::tr("Qt Declarative UI Runtime"), warnings);
+ }
+}
+
+void myMessageOutput(QtMsgType type, const char *msg)
+{
+ if (!logger.isNull()) {
+ QString strMsg = QString::fromAscii(msg);
+ QMetaObject::invokeMethod(logger.data(), "append", Q_ARG(QString, strMsg));
+ } else {
+ warnings += msg;
+ warnings += QLatin1Char('\n');
+ }
+ if (systemMsgOutput) { // Windows
+ systemMsgOutput(type, msg);
+ } else { // Unix
+ fprintf(stderr, "%s\n",msg);
+ fflush(stderr);
+ }
+}
+
#endif
void usage()
@@ -91,6 +125,7 @@ void usage()
qWarning(" -sizeviewtorootobject .................... the view resizes to the changes in the content");
qWarning(" -sizerootobjecttoview .................... the content resizes to the changes in the view");
qWarning(" -qmlbrowser .............................. use a QML-based file browser");
+ qWarning(" -nolog ................................... do not show log window");
qWarning(" -recordfile <output> ..................... set video recording file");
qWarning(" - ImageMagick 'convert' for GIF)");
qWarning(" - png file for raw frames");
@@ -137,6 +172,14 @@ int main(int argc, char ** argv)
{
#if defined (Q_OS_SYMBIAN)
qInstallMsgHandler(myMessageOutput);
+#else
+ systemMsgOutput = qInstallMsgHandler(myMessageOutput);
+#endif
+
+#if defined (Q_OS_WIN)
+ // Debugging output is not visible by default on Windows -
+ // therefore show modal dialog with errors instad.
+ atexit(showWarnings);
#endif
#if defined (Q_WS_X11)
@@ -186,6 +229,7 @@ int main(int argc, char ** argv)
bool stayOnTop = false;
bool maximized = false;
bool useNativeFileBrowser = true;
+ bool showLogWidget = true;
bool sizeToView = true;
#if defined(Q_OS_SYMBIAN)
@@ -237,8 +281,8 @@ int main(int argc, char ** argv)
if (lastArg) usage();
app.setStartDragDistance(QString(argv[++i]).toInt());
} else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) {
- fprintf(stderr, "Qt Declarative UI Viewer version %s\n", QT_VERSION_STR);
- return 0;
+ qWarning("Qt Declarative UI Viewer version %s", QT_VERSION_STR);
+ exit(0);
} else if (arg == "-translation") {
if (lastArg) usage();
translationFile = argv[++i];
@@ -246,14 +290,16 @@ int main(int argc, char ** argv)
useGL = true;
} else if (arg == "-qmlbrowser") {
useNativeFileBrowser = false;
+ } else if (arg == "-nolog") {
+ showLogWidget = false;
} else if (arg == "-I" || arg == "-L") {
if (arg == "-L")
- fprintf(stderr, "-L option provided for compatibility only, use -I instead");
+ qWarning("-L option provided for compatibility only, use -I instead");
if (lastArg) {
QDeclarativeEngine tmpEngine;
QString paths = tmpEngine.importPathList().join(QLatin1String(":"));
- fprintf(stderr, "Current search path: %s\n", paths.toLocal8Bit().constData());
- return 0;
+ qWarning("Current search path: %s", paths.toLocal8Bit().constData());
+ exit(0);
}
imports << QString(argv[++i]);
} else if (arg == "-P") {
@@ -294,7 +340,14 @@ int main(int argc, char ** argv)
if (stayOnTop)
wflags |= Qt::WindowStaysOnTopHint;
- QDeclarativeViewer viewer(0, wflags);
+#if !defined(Q_OS_SYMBIAN)
+ LoggerWidget loggerWidget(0);
+ if (showLogWidget) {
+ logger = &loggerWidget;
+ }
+#endif
+
+ QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags);
if (!scriptopts.isEmpty()) {
QStringList options =
scriptopts.split(QLatin1Char(','), QString::SkipEmptyParts);
@@ -330,45 +383,45 @@ int main(int argc, char ** argv)
if (!(scriptOptions & QDeclarativeViewer::Record) && !(scriptOptions & QDeclarativeViewer::Play))
scriptOptsUsage();
- viewer.setScriptOptions(scriptOptions);
- viewer.setScript(script);
+ viewer->setScriptOptions(scriptOptions);
+ viewer->setScript(script);
} else if (!script.isEmpty()) {
usage();
}
- viewer.addLibraryPath(QCoreApplication::applicationDirPath());
+ viewer->addLibraryPath(QCoreApplication::applicationDirPath());
foreach (QString lib, imports)
- viewer.addLibraryPath(lib);
+ viewer->addLibraryPath(lib);
foreach (QString plugin, plugins)
- viewer.addPluginPath(plugin);
+ viewer->addPluginPath(plugin);
- viewer.setNetworkCacheSize(cache);
- viewer.setRecordFile(recordfile);
- viewer.setSizeToView(sizeToView);
+ viewer->setNetworkCacheSize(cache);
+ viewer->setRecordFile(recordfile);
+ viewer->setSizeToView(sizeToView);
if (resizeview)
- viewer.setScaleView();
+ viewer->setScaleView();
if (fps>0)
- viewer.setRecordRate(fps);
+ viewer->setRecordRate(fps);
if (autorecord_to)
- viewer.setAutoRecord(autorecord_from,autorecord_to);
+ viewer->setAutoRecord(autorecord_from,autorecord_to);
if (!skin.isEmpty()) {
if (skin == "list") {
- foreach (QString s, viewer.builtinSkins())
+ foreach (QString s, viewer->builtinSkins())
qWarning() << qPrintable(s);
exit(0);
} else {
- viewer.setSkin(skin);
+ viewer->setSkin(skin);
}
}
if (devkeys)
- viewer.setDeviceKeys(true);
- viewer.setRecordDither(dither);
+ viewer->setDeviceKeys(true);
+ viewer->setRecordDither(dither);
if (recordargs.count())
- viewer.setRecordArgs(recordargs);
+ viewer->setRecordArgs(recordargs);
- viewer.setUseNativeFileBrowser(useNativeFileBrowser);
+ viewer->setUseNativeFileBrowser(useNativeFileBrowser);
if (fullScreen && maximized)
qWarning() << "Both -fullscreen and -maximized specified. Using -fullscreen.";
@@ -387,16 +440,19 @@ int main(int argc, char ** argv)
}
if (!fileName.isEmpty()) {
- viewer.open(fileName);
- fullScreen ? viewer.showFullScreen() : maximized ? viewer.showMaximized() : viewer.show();
+ viewer->open(fileName);
+ fullScreen ? viewer->showFullScreen() : maximized ? viewer->showMaximized() : viewer->show();
} else {
if (!useNativeFileBrowser)
- viewer.openFile();
- fullScreen ? viewer.showFullScreen() : maximized ? viewer.showMaximized() : viewer.show();
+ viewer->openFile();
+ fullScreen ? viewer->showFullScreen() : maximized ? viewer->showMaximized() : viewer->show();
if (useNativeFileBrowser)
- viewer.openFile();
+ viewer->openFile();
}
- viewer.setUseGL(useGL);
- viewer.raise();
- return app.exec();
+ viewer->setUseGL(useGL);
+ viewer->raise();
+
+ int rv = app.exec();
+ delete viewer;
+ exit(rv);
}