From 2b0266d0ee39d7e599f386d180aaafaa81a4fcb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 14 Apr 2011 15:00:42 +0200 Subject: [PATCH] Disable observer and jsdebugger services when they're already part of Qt As of Qt 4.8 the observer and jsdebugger services are part of Qt. This means the following changes are necessary in Qt Creator: * Do not link to the QmlJSDebugger library. * Do not create JSDebuggerAgent and QDeclarativeViewObserver instances in the QmlApplicationViewer and use the new declarative_debug CONFIG option to enable those services in Qt. This is done automatically for debug builds. * Point out the QML Debugging Library and the QML Observer are "Not needed" in the Qt options page. * Change the label in qmake options from "Link QML debugging library" to "Enable QML debugging". It still remains as a way to enable this functionality in release builds or for QtQuick applications not based on Qt Creator's template. * Rely on qmlviewer for debugging QML UI projects rather than the observer, which is no longer necessary. Reviewed-by: Kai Koehne --- .../qmlapplicationviewer.cpp | 17 ++--- .../qmlapplicationviewer.pri | 1 + .../qmlprojectrunconfiguration.cpp | 2 + .../qmlprojectruncontrol.cpp | 3 +- .../qt4projectmanager/baseqtversion.cpp | 6 ++ src/plugins/qt4projectmanager/baseqtversion.h | 1 + src/plugins/qt4projectmanager/qmakestep.cpp | 67 +++++++++++-------- src/plugins/qt4projectmanager/qmakestep.h | 2 +- src/plugins/qt4projectmanager/qmakestep.ui | 4 +- .../qt4projectmanager/qtoptionspage.cpp | 16 +++-- .../qt4projectmanager/wizards/qtquickapp.cpp | 2 +- 11 files changed, 75 insertions(+), 46 deletions(-) diff --git a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp index b12fbcd8c4..be7ce4ec06 100644 --- a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp +++ b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp @@ -16,19 +16,17 @@ #include #include -#if defined(QMLJSDEBUGGER) +#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 + #include -#endif -#if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER) +#if !defined(NO_JSDEBUGGER) #include #endif -#if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER) +#if !defined(NO_QMLOBSERVER) #include #endif -#if defined(QMLJSDEBUGGER) - // Enable debugging before any QDeclarativeEngine is created struct QmlJsDebuggingEnabler { @@ -76,12 +74,15 @@ QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) : { connect(engine(), SIGNAL(quit()), SLOT(close())); setResizeMode(QDeclarativeView::SizeRootObjectToView); -#if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER) + // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in +#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 +#if !defined(NO_JSDEBUGGER) new QmlJSDebugger::JSDebuggerAgent(engine()); #endif -#if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER) +#if !defined(NO_QMLOBSERVER) new QmlJSDebugger::QDeclarativeViewObserver(this, this); #endif +#endif } QmlApplicationViewer::~QmlApplicationViewer() diff --git a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.pri b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.pri index 6704a74c1b..29006f5a79 100644 --- a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.pri +++ b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.pri @@ -5,6 +5,7 @@ # may offer an updated version of it. QT += declarative +CONFIG(debug, debug|release):CONFIG += declarative_debug SOURCES += $$PWD/qmlapplicationviewer.cpp HEADERS += $$PWD/qmlapplicationviewer.h diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp index 760927bb99..b621cea496 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp @@ -134,6 +134,8 @@ QString QmlProjectRunConfiguration::observerPath() const if (!version) { return QString(); } else { + if (!version->needsQmlDebuggingLibrary()) + return version->qmlviewerCommand(); return version->qmlObserverTool(); } } diff --git a/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp index f6ee63c239..058b215d7d 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp @@ -160,7 +160,8 @@ bool QmlProjectRunControlFactory::canRun(RunConfiguration *runConfiguration, Debugger::DebuggerPlugin::isActiveDebugLanguage(Debugger::QmlLanguage); if (config && qmlDebugSupportInstalled) { - if (!config->observerPath().isEmpty()) + if (!(config->qtVersion() && config->qtVersion()->needsQmlDebuggingLibrary()) + || !config->observerPath().isEmpty()) return true; if (config->qtVersion() && Qt4ProjectManager::QmlObserverTool::canBuild(config->qtVersion())) return true; diff --git a/src/plugins/qt4projectmanager/baseqtversion.cpp b/src/plugins/qt4projectmanager/baseqtversion.cpp index c4db89c1bb..c2fcd347d6 100644 --- a/src/plugins/qt4projectmanager/baseqtversion.cpp +++ b/src/plugins/qt4projectmanager/baseqtversion.cpp @@ -784,6 +784,12 @@ bool BaseQtVersion::hasQmlDebuggingLibrary() const return m_hasQmlDebuggingLibrary; } +bool BaseQtVersion::needsQmlDebuggingLibrary() const +{ + updateVersionInfo(); + return qtVersion() < QtVersionNumber(4, 8, 0); +} + bool BaseQtVersion::hasQmlObserver() const { updateVersionInfo(); diff --git a/src/plugins/qt4projectmanager/baseqtversion.h b/src/plugins/qt4projectmanager/baseqtversion.h index e53f4a0b45..67943e4f93 100644 --- a/src/plugins/qt4projectmanager/baseqtversion.h +++ b/src/plugins/qt4projectmanager/baseqtversion.h @@ -181,6 +181,7 @@ public: virtual bool hasGdbDebuggingHelper() const; virtual bool hasQmlDump() const; virtual bool hasQmlDebuggingLibrary() const; + virtual bool needsQmlDebuggingLibrary() const; virtual bool hasQmlObserver() const; Utils::Environment qmlToolsEnvironment() const; diff --git a/src/plugins/qt4projectmanager/qmakestep.cpp b/src/plugins/qt4projectmanager/qmakestep.cpp index 6fefa1712c..f9de9c62a6 100644 --- a/src/plugins/qt4projectmanager/qmakestep.cpp +++ b/src/plugins/qt4projectmanager/qmakestep.cpp @@ -163,14 +163,22 @@ QStringList QMakeStep::moreArguments() arguments << QLatin1String("-unix"); #endif - if (m_linkQmlDebuggingLibrary - && bc->qtVersion() && !bc->qtVersion()->qmlDebuggingHelperLibrary(true).isEmpty()) { - // Do not turn debugger path into native path separators: Qmake does not like that! - const QString debuggingHelperPath - = QFileInfo(bc->qtVersion()->qmlDebuggingHelperLibrary(true)).dir().path(); - - arguments << QLatin1String(Constants::QMAKEVAR_QMLJSDEBUGGER_PATH) - + QLatin1Char('=') + debuggingHelperPath; + if (m_linkQmlDebuggingLibrary && bc->qtVersion()) { + if (!bc->qtVersion()->needsQmlDebuggingLibrary()) { + // This Qt version has the QML debugging services built in, however + // they still need to be enabled at compile time + arguments << QLatin1String("CONFIG+=declarative_debug"); + } else { + QString qmlDebuggingHelperLibrary = bc->qtVersion()->qmlDebuggingHelperLibrary(true); + if (!qmlDebuggingHelperLibrary.isEmpty()) { + // Do not turn debugger path into native path separators: Qmake does not like that! + const QString debuggingHelperPath + = QFileInfo(qmlDebuggingHelperLibrary).dir().path(); + + arguments << QLatin1String(Constants::QMAKEVAR_QMLJSDEBUGGER_PATH) + + QLatin1Char('=') + debuggingHelperPath; + } + } } if (bc->qtVersion() && !bc->qtVersion()->supportsShadowBuilds()) { @@ -339,7 +347,8 @@ bool QMakeStep::isQmlDebuggingLibrarySupported(QString *reason) const *reason = tr("No Qt version."); return false; } - if (version->hasQmlDebuggingLibrary()) + + if (!version->needsQmlDebuggingLibrary() || version->hasQmlDebuggingLibrary()) return true; if (!version->qtAbis().isEmpty()) { @@ -447,14 +456,13 @@ QMakeStepConfigWidget::QMakeStepConfigWidget(QMakeStep *step) void QMakeStepConfigWidget::init() { m_ui.qmakeAdditonalArgumentsLineEdit->setText(m_step->userArguments()); - m_ui.qmlDebuggingLibraryCheckBox->setEnabled(m_step->isQmlDebuggingLibrarySupported()); m_ui.qmlDebuggingLibraryCheckBox->setChecked(m_step->linkQmlDebuggingLibrary()); qmakeBuildConfigChanged(); updateSummaryLabel(); updateEffectiveQMakeCall(); - updateQmlDebuggingWarningsLabel(); + updateQmlDebuggingOption(); } QString QMakeStepConfigWidget::summaryText() const @@ -471,7 +479,7 @@ void QMakeStepConfigWidget::qtVersionChanged() { updateSummaryLabel(); updateEffectiveQMakeCall(); - updateQmlDebuggingWarningsLabel(); + updateQmlDebuggingOption(); } void QMakeStepConfigWidget::qmakeBuildConfigChanged() @@ -507,7 +515,7 @@ void QMakeStepConfigWidget::linkQmlDebuggingLibraryChanged() updateSummaryLabel(); updateEffectiveQMakeCall(); - updateQmlDebuggingWarningsLabel(); + updateQmlDebuggingOption(); } void QMakeStepConfigWidget::qmakeArgumentsLineEdited() @@ -557,7 +565,7 @@ void QMakeStepConfigWidget::linkQmlDebuggingLibraryChecked(bool checked) updateSummaryLabel(); updateEffectiveQMakeCall(); - updateQmlDebuggingWarningsLabel(); + updateQmlDebuggingOption(); } void QMakeStepConfigWidget::buildQmlDebuggingHelper() @@ -587,10 +595,9 @@ void QMakeStepConfigWidget::debuggingHelperBuildFinished(int qtVersionId, const if (version == m_step->qt4BuildConfiguration()->qtVersion()) { m_ui.qmlDebuggingLibraryCheckBox->setChecked(m_step->linkQmlDebuggingLibrary()); - m_ui.qmlDebuggingLibraryCheckBox->setEnabled(m_step->isQmlDebuggingLibrarySupported()); updateSummaryLabel(); updateEffectiveQMakeCall(); - updateQmlDebuggingWarningsLabel(); + updateQmlDebuggingOption(); } @@ -619,21 +626,25 @@ void QMakeStepConfigWidget::updateSummaryLabel() } -void QMakeStepConfigWidget::updateQmlDebuggingWarningsLabel() +void QMakeStepConfigWidget::updateQmlDebuggingOption() { - QString reason; - m_ui.qmlDebuggingWarningText->clear(); - if (!m_step->isQmlDebuggingLibrarySupported(&reason)) { - m_ui.qmlDebuggingWarningText->setText(reason); - } + m_ui.qmlDebuggingLibraryCheckBox->setEnabled(m_step->isQmlDebuggingLibrarySupported()); - if (m_step->linkQmlDebuggingLibrary()) { - if (m_step->isQmlDebuggingLibrarySupported()) { - m_ui.qmlDebuggingWarningText->setText(tr("Might make the application vulnerable. Use only in a safe environment.")); - } - } + BaseQtVersion *qtVersion = m_step->qt4BuildConfiguration()->qtVersion(); + if (!qtVersion || !qtVersion->needsQmlDebuggingLibrary()) + m_ui.debuggingLibraryLabel->setText(tr("Enable QML debugging:")); + else + m_ui.debuggingLibraryLabel->setText(tr("Link QML debugging library:")); + + QString warningText; + + if (!m_step->isQmlDebuggingLibrarySupported(&warningText)) + ; + else if (m_step->linkQmlDebuggingLibrary()) + warningText = tr("Might make your application vulnerable. Only use in a safe environment!"); - m_ui.qmlDebuggingWarningIcon->setVisible(!m_ui.qmlDebuggingWarningText->text().isEmpty()); + m_ui.qmlDebuggingWarningText->setText(warningText); + m_ui.qmlDebuggingWarningIcon->setVisible(!warningText.isEmpty()); } void QMakeStepConfigWidget::updateEffectiveQMakeCall() diff --git a/src/plugins/qt4projectmanager/qmakestep.h b/src/plugins/qt4projectmanager/qmakestep.h index 3797119e4e..69ac9cf30c 100644 --- a/src/plugins/qt4projectmanager/qmakestep.h +++ b/src/plugins/qt4projectmanager/qmakestep.h @@ -152,7 +152,7 @@ private slots: private: void updateSummaryLabel(); - void updateQmlDebuggingWarningsLabel(); + void updateQmlDebuggingOption(); void updateEffectiveQMakeCall(); Ui::QMakeStep m_ui; QMakeStep *m_step; diff --git a/src/plugins/qt4projectmanager/qmakestep.ui b/src/plugins/qt4projectmanager/qmakestep.ui index 8c877916d7..54d5aeeb00 100644 --- a/src/plugins/qt4projectmanager/qmakestep.ui +++ b/src/plugins/qt4projectmanager/qmakestep.ui @@ -56,7 +56,7 @@ - + Qt::Horizontal @@ -82,7 +82,7 @@ - + Link QML debugging library: diff --git a/src/plugins/qt4projectmanager/qtoptionspage.cpp b/src/plugins/qt4projectmanager/qtoptionspage.cpp index 15eaa75192..cf4d7ae285 100644 --- a/src/plugins/qt4projectmanager/qtoptionspage.cpp +++ b/src/plugins/qt4projectmanager/qtoptionspage.cpp @@ -474,6 +474,7 @@ void QtOptionsPageWidget::updateDebuggingHelperUi() const bool hasGdbHelper = !version->gdbDebuggingHelperLibrary().isEmpty(); const bool hasQmlDumper = version->hasQmlDump(); const bool hasQmlDebuggingLib = version->hasQmlDebuggingLibrary(); + const bool needsQmlDebuggingLib = version->needsQmlDebuggingLibrary(); const bool hasQmlObserver = !version->qmlObserverTool().isEmpty(); bool isBuildingGdbHelper = false; @@ -566,8 +567,10 @@ void QtOptionsPageWidget::updateDebuggingHelperUi() qmlDebuggingLibStatusText += debugPath; } qmlDebuggingLibStatusTextFlags = Qt::TextSelectableByMouse; - } else { - if (canBuildQmlDebuggingLib) { + } else { + if (!needsQmlDebuggingLib) { + qmlDebuggingLibStatusText = tr("Not needed."); + } else if (canBuildQmlDebuggingLib) { qmlDebuggingLibStatusText = tr("Not yet built."); } else { qmlDebuggingLibStatusText = tr("Cannot be compiled."); @@ -575,7 +578,8 @@ void QtOptionsPageWidget::updateDebuggingHelperUi() } m_debuggingHelperUi->qmlDebuggingLibStatus->setText(qmlDebuggingLibStatusText); m_debuggingHelperUi->qmlDebuggingLibStatus->setTextInteractionFlags(qmlDebuggingLibStatusTextFlags); - m_debuggingHelperUi->qmlDebuggingLibBuildButton->setEnabled(canBuildQmlDebuggingLib + m_debuggingHelperUi->qmlDebuggingLibBuildButton->setEnabled(needsQmlDebuggingLib + && canBuildQmlDebuggingLib && !isBuildingQmlDebuggingLib); QString qmlObserverStatusText; @@ -584,7 +588,9 @@ void QtOptionsPageWidget::updateDebuggingHelperUi() qmlObserverStatusText = QDir::toNativeSeparators(version->qmlObserverTool()); qmlObserverStatusTextFlags = Qt::TextSelectableByMouse; } else { - if (canBuildQmlObserver) { + if (!needsQmlDebuggingLib) { + qmlObserverStatusText = tr("Not needed."); + } else if (canBuildQmlObserver) { qmlObserverStatusText = tr("Not yet built."); } else { qmlObserverStatusText = tr("Cannot be compiled."); @@ -604,7 +610,7 @@ void QtOptionsPageWidget::updateDebuggingHelperUi() && !isBuildingQmlObserver) && (canBuildGdbHelper || canBuildQmlDumper - || canBuildQmlDebuggingLib + || (canBuildQmlDebuggingLib && needsQmlDebuggingLib) || canBuildQmlObserver)); m_ui->debuggingHelperWidget->setVisible(true); diff --git a/src/plugins/qt4projectmanager/wizards/qtquickapp.cpp b/src/plugins/qt4projectmanager/wizards/qtquickapp.cpp index a46d64fb13..47786470c6 100644 --- a/src/plugins/qt4projectmanager/wizards/qtquickapp.cpp +++ b/src/plugins/qt4projectmanager/wizards/qtquickapp.cpp @@ -417,7 +417,7 @@ QList QtQuickApp::deploymentFolders() const return result; } -const int QtQuickApp::StubVersion = 11; +const int QtQuickApp::StubVersion = 12; } // namespace Internal } // namespace Qt4ProjectManager -- GitLab