From 813135081a8e22b673d2673fc38884b595ec0d33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Mon, 18 Apr 2011 17:20:49 +0200 Subject: [PATCH] Introduced a CONFIG option that enables declarative debug services This replaces the need for applications to explicitly make a call to enable the debug services, and rather does it in declarative.h when the 'declarative_debug' CONFIG option is used. Done-with: Kai Koehne Reviewed-by: Martin Jones Reviewed-by: Michael Brasser (cherry picked from commit 5517cc588c39814530b8bfd957821f55be42acf2) Change-Id: Iacfc5a9b2ca0c2610288cf86f190b4a9950cacd1 Reviewed-on: http://codereview.qt.nokia.com/2436 Reviewed-by: Qt Sanity Bot Reviewed-by: Martin Jones --- src/declarative/qml/qdeclarative.h | 11 +++++++++++ src/declarative/qml/qdeclarativeengine.cpp | 11 +++++++++++ tools/qmlscene/main.cpp | 2 -- tools/qmlscene/qmlscene.pro | 2 +- tools/qmlviewer/main.cpp | 3 --- tools/qmlviewer/qmlviewer.pro | 2 +- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/declarative/qml/qdeclarative.h b/src/declarative/qml/qdeclarative.h index 4c962f8..311ecd3 100644 --- a/src/declarative/qml/qdeclarative.h +++ b/src/declarative/qml/qdeclarative.h @@ -550,6 +550,17 @@ inline int qmlRegisterModuleApi(const char *uri, int versionMajor, int versionMi return QDeclarativePrivate::qmlregister(QDeclarativePrivate::ModuleApiRegistration, &api); } +// Enable debugging before any QDeclarativeEngine is created +struct Q_DECLARATIVE_EXPORT QDeclarativeDebuggingEnabler +{ + QDeclarativeDebuggingEnabler(); +}; + +// Execute code in constructor before first QDeclarativeEngine is instantiated +#if defined(QT_DECLARATIVE_DEBUG) +static QDeclarativeDebuggingEnabler qmlEnableDebuggingHelper; +#endif + QT_END_NAMESPACE QML_DECLARE_TYPE(QObject) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index a2f724e..e62f07c 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -992,6 +992,17 @@ QObject *qmlAttachedPropertiesObject(int *idCache, const QObject *object, return qmlAttachedPropertiesObjectById(*idCache, object, create); } +QDeclarativeDebuggingEnabler::QDeclarativeDebuggingEnabler() +{ +#ifndef QDECLARATIVE_NO_DEBUG_PROTOCOL + if (!QDeclarativeEnginePrivate::qml_debugging_enabled) { + qWarning("Qml debugging is enabled. Only use this in a safe environment!"); + } + QDeclarativeEnginePrivate::qml_debugging_enabled = true; +#endif +} + + class QDeclarativeDataExtended { public: QDeclarativeDataExtended(); diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp index 0d6f813..e6603ad 100644 --- a/tools/qmlscene/main.cpp +++ b/tools/qmlscene/main.cpp @@ -56,7 +56,6 @@ #include #include -#include // ### This should be private API #include @@ -455,7 +454,6 @@ int main(int argc, char ** argv) Options options; - QDeclarativeDebugHelper::enableDebugging(); QStringList imports; for (int i = 1; i < argc; ++i) { if (*argv[i] != '-' && QFileInfo(argv[i]).exists()) diff --git a/tools/qmlscene/qmlscene.pro b/tools/qmlscene/qmlscene.pro index 8e252e5..7a72263 100644 --- a/tools/qmlscene/qmlscene.pro +++ b/tools/qmlscene/qmlscene.pro @@ -11,7 +11,7 @@ macx: CONFIG -= app_bundle SOURCES += main.cpp -CONFIG += console +CONFIG += console declarative_debug symbian { TARGET.EPOCHEAPSIZE = 0x20000 0x5000000 diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index bf99fa5..cf33c4e 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -52,7 +52,6 @@ #include #include #include "qdeclarativetester.h" -#include QT_USE_NAMESPACE @@ -539,8 +538,6 @@ int main(int argc, char ** argv) QApplication::setGraphicsSystem(QLatin1String("raster")); #endif - QDeclarativeDebugHelper::enableDebugging(); - Application app(argc, argv); app.setApplicationName(QLatin1String("QtQmlViewer")); app.setOrganizationName(QLatin1String("Nokia")); diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro index 16579bb..991d07c 100644 --- a/tools/qmlviewer/qmlviewer.pro +++ b/tools/qmlviewer/qmlviewer.pro @@ -1,5 +1,5 @@ TEMPLATE = app -CONFIG += qt uic +CONFIG += qt uic declarative_debug DESTDIR = ../../bin QT += declarative qtquick1 qtquick1-private -- 1.7.2.5