diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2010-04-19 07:08:28 (GMT) |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2010-04-20 13:00:01 (GMT) |
commit | 831b27e8fb9d12345c33315b7d7c08b613e3d4bb (patch) | |
tree | f124210d62ffa0f2e5980f3471c7a2b8b8d1e752 | |
parent | 76670cb51e53140ccd2873e627708dc73c12d9b3 (diff) | |
download | Qt-831b27e8fb9d12345c33315b7d7c08b613e3d4bb.zip Qt-831b27e8fb9d12345c33315b7d7c08b613e3d4bb.tar.gz Qt-831b27e8fb9d12345c33315b7d7c08b613e3d4bb.tar.bz2 |
Show command line help / qml runtime output in GUI
Since qml is a GUI program, debugging output isn't visible by default
for Windows/Mac users. Therefore provide command line help in a dialog (Windows), and runtime errors/warnings in a separate top level window.
Done together with mae.
Reviewed-by: mae
-rw-r--r-- | tools/qml/loggerwidget.cpp | 29 | ||||
-rw-r--r-- | tools/qml/loggerwidget.h | 21 | ||||
-rw-r--r-- | tools/qml/main.cpp | 67 | ||||
-rw-r--r-- | tools/qml/qml.pri | 7 | ||||
-rw-r--r-- | tools/qml/qmlruntime.cpp | 1 |
5 files changed, 114 insertions, 11 deletions
diff --git a/tools/qml/loggerwidget.cpp b/tools/qml/loggerwidget.cpp new file mode 100644 index 0000000..df94ba0 --- /dev/null +++ b/tools/qml/loggerwidget.cpp @@ -0,0 +1,29 @@ +#include "loggerwidget.h" +#include <qglobal.h> +#include <QDebug> + +QT_BEGIN_NAMESPACE + +LoggerWidget::LoggerWidget(QWidget *parent) : + QPlainTextEdit(parent), + m_keepClosed(false) +{ + setAttribute(Qt::WA_QuitOnClose, false); + setWindowTitle(tr("Qt Declarative UI Viewer - Logger")); +} + +void LoggerWidget::append(QtMsgType /*type*/, const char *msg) +{ + appendPlainText(QString::fromAscii(msg)); + + if (!m_keepClosed && !isVisible()) + setVisible(true); +} + +void LoggerWidget::closeEvent(QCloseEvent *event) +{ + m_keepClosed = true; + QWidget::closeEvent(event); +} + +QT_END_NAMESPACE diff --git a/tools/qml/loggerwidget.h b/tools/qml/loggerwidget.h new file mode 100644 index 0000000..0e47f33 --- /dev/null +++ b/tools/qml/loggerwidget.h @@ -0,0 +1,21 @@ +#ifndef LOGGERWIDGET_H +#define LOGGERWIDGET_H + +#include <QPlainTextEdit> + +QT_BEGIN_NAMESPACE + +class LoggerWidget : public QPlainTextEdit { +Q_OBJECT +public: + LoggerWidget(QWidget *parent=0); + void append(QtMsgType type, const char *msg); +protected: + void closeEvent(QCloseEvent *event); +private: + bool m_keepClosed; +}; + +QT_END_NAMESPACE + +#endif // LOGGERWIDGET_H diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 15e8f64..19f92bd 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/* ** ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. @@ -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,35 @@ 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()) { + logger.data()->append(type, msg); + } 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 +124,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 +171,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 +228,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 +280,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 +289,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\n"); + 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,6 +339,13 @@ int main(int argc, char ** argv) if (stayOnTop) wflags |= Qt::WindowStaysOnTopHint; +#if !defined(Q_OS_SYMBIAN) + LoggerWidget loggerWidget(0); + if (showLogWidget) { + logger = &loggerWidget; + } +#endif + QDeclarativeViewer viewer(0, wflags); if (!scriptopts.isEmpty()) { QStringList options = @@ -398,5 +450,6 @@ int main(int argc, char ** argv) } viewer.setUseGL(useGL); viewer.raise(); - return app.exec(); + + exit(app.exec()); } diff --git a/tools/qml/qml.pri b/tools/qml/qml.pri index c48e919..d343c76 100644 --- a/tools/qml/qml.pri +++ b/tools/qml/qml.pri @@ -10,11 +10,13 @@ HEADERS += $$PWD/qmlruntime.h \ $$PWD/proxysettings.h \ $$PWD/qdeclarativetester.h \ $$PWD/deviceorientation.h \ - $$PWD/qdeclarativefolderlistmodel.h + $$PWD/qdeclarativefolderlistmodel.h \ + $$PWD/loggerwidget.h SOURCES += $$PWD/qmlruntime.cpp \ $$PWD/proxysettings.cpp \ $$PWD/qdeclarativetester.cpp \ - $$PWD/qdeclarativefolderlistmodel.cpp + $$PWD/qdeclarativefolderlistmodel.cpp \ + $$PWD/loggerwidget.cpp RESOURCES = $$PWD/qmlruntime.qrc maemo5 { @@ -26,4 +28,3 @@ FORMS = $$PWD/recopts.ui \ $$PWD/proxysettings.ui include(../shared/deviceskin/deviceskin.pri) - diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 68940c7..87a4d21 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -1000,7 +1000,6 @@ bool QDeclarativeViewer::open(const QString& file_or_url) t.start(); canvas->setSource(url); - qWarning() << "Wall startup time:" << t.elapsed(); return true; } |