From 5fb18dcc83cee40bb2abe00cd2db680911a9c2e4 Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Fri, 10 Jun 2011 17:09:45 +0200
Subject: [PATCH] QmlProfiler: Warn user if Qt is too old

Check for the Qt version in teh active build configuration. If
it's too old warn the user that we require 4.7.4.

(The app running doesn't necessarily have to have the same Qt version,
so this is just an approximation).

Change-Id: Id1f31e4f0734448712dd48ecf6526ca89da45b8b
Reviewed-on: http://codereview.qt.nokia.com/460
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
---
 .../analyzerbase/analyzerruncontrol.cpp       | 12 +++++++++++-
 src/plugins/qmlprofiler/qmlprofilertool.cpp   | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/plugins/analyzerbase/analyzerruncontrol.cpp b/src/plugins/analyzerbase/analyzerruncontrol.cpp
index ecd90fe3f36..ad1fb6bb0b1 100644
--- a/src/plugins/analyzerbase/analyzerruncontrol.cpp
+++ b/src/plugins/analyzerbase/analyzerruncontrol.cpp
@@ -75,6 +75,9 @@ AnalyzerRunControl::AnalyzerRunControl(const AnalyzerStartParameters &sp,
     IAnalyzerTool *tool = AnalyzerManager::instance()->currentTool();
     d->m_engine = tool->createEngine(sp, runConfiguration);
 
+    if (!d->m_engine)
+        return;
+
     connect(d->m_engine, SIGNAL(outputReceived(QString,Utils::OutputFormat)),
             SLOT(receiveOutput(QString,Utils::OutputFormat)));
     connect(d->m_engine, SIGNAL(taskToBeAdded(ProjectExplorer::Task::TaskType,QString,QString,int)),
@@ -94,6 +97,11 @@ AnalyzerRunControl::~AnalyzerRunControl()
 
 void AnalyzerRunControl::start()
 {
+    if (!d->m_engine) {
+        emit finished();
+        return;
+    }
+
     // clear about-to-be-outdated tasks
     ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
     ProjectExplorer::TaskHub *hub = pm->getObject<ProjectExplorer::TaskHub>();
@@ -106,7 +114,7 @@ void AnalyzerRunControl::start()
 
 ProjectExplorer::RunControl::StopResult AnalyzerRunControl::stop()
 {
-    if (!d->m_isRunning)
+    if (!d->m_engine || !d->m_isRunning)
         return StoppedSynchronously;
 
     d->m_engine->stop();
@@ -127,6 +135,8 @@ bool AnalyzerRunControl::isRunning() const
 
 QString AnalyzerRunControl::displayName() const
 {
+    if (!d->m_engine)
+        return QString();
     return d->m_engine->startParameters().displayName;
 }
 
diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp
index 791708f82ae..13f27f8b75d 100644
--- a/src/plugins/qmlprofiler/qmlprofilertool.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp
@@ -68,14 +68,17 @@
 #include <coreplugin/editormanager/editormanager.h>
 #include <coreplugin/icore.h>
 
+#include <qt4projectmanager/qt4buildconfiguration.h>
 #include <qt4projectmanager/qt-s60/s60deployconfiguration.h>
 
 #include <QtCore/QFile>
 
+#include <QtGui/QApplication>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QLabel>
 #include <QtGui/QTabWidget>
 #include <QtGui/QToolButton>
+#include <QtGui/QMessageBox>
 
 using namespace Analyzer;
 using namespace QmlProfiler::Internal;
@@ -156,6 +159,22 @@ IAnalyzerEngine *QmlProfilerTool::createEngine(const AnalyzerStartParameters &sp
 {
     QmlProfilerEngine *engine = new QmlProfilerEngine(sp, runConfiguration);
 
+    // Check minimum Qt Version. We cannot really be sure what the Qt version at runtime is,
+    // but guess that the active build configuraiton has been used.
+    QtSupport::QtVersionNumber minimumVersion(4,7,4);
+    if (Qt4ProjectManager::Qt4BuildConfiguration *qt4Config
+            = qobject_cast<Qt4ProjectManager::Qt4BuildConfiguration*>(
+                runConfiguration->target()->activeBuildConfiguration())) {
+        if (qt4Config->qtVersion()->isValid() && qt4Config->qtVersion()->qtVersion() < minimumVersion) {
+            int result = QMessageBox::warning(QApplication::activeWindow(), tr("QML Profiler"),
+                                 "The QML profiler requires Qt 4.7.4 or newer.\n"
+                                 "The Qt version configured in your active build configuration is too old.\n"
+                                 "Do you want to continue?", QMessageBox::Yes, QMessageBox::No);
+            if (result == QMessageBox::No)
+                return 0;
+        }
+    }
+
     d->m_connectMode = QmlProfilerToolPrivate::TcpConnection;
 
     if (Qt4ProjectManager::S60DeployConfiguration *deployConfig
-- 
GitLab