diff --git a/src/plugins/qmlinspector/qmlinspector.pro b/src/plugins/qmlinspector/qmlinspector.pro
index 7e9a4f1214fd9c5397d4f5e8ce7ede804e13bfd4..55becbd1b6e217b59c6efc67e682acd67f4a58c0 100644
--- a/src/plugins/qmlinspector/qmlinspector.pro
+++ b/src/plugins/qmlinspector/qmlinspector.pro
@@ -9,13 +9,11 @@ include(components/qmldebugger.pri)
 HEADERS += qmlinspectorplugin.h \
            qmlinspector.h \
            qmlinspectormode.h \
-           inspectoroutputpane.h \
-           runcontrol.h
+           inspectoroutputpane.h
 
 SOURCES += qmlinspectorplugin.cpp \
            qmlinspectormode.cpp \
-           inspectoroutputpane.cpp \
-           runcontrol.cpp 
+           inspectoroutputpane.cpp
 
 OTHER_FILES += QmlInspector.pluginspec
 RESOURCES += qmlinspector.qrc
diff --git a/src/plugins/qmlinspector/qmlinspectormode.cpp b/src/plugins/qmlinspector/qmlinspectormode.cpp
index 69da5c2a054db15f37202036b0e37ba8246aaa1f..7af3a4fdb9110dee0d187c9b14507ab167fa30f3 100644
--- a/src/plugins/qmlinspector/qmlinspectormode.cpp
+++ b/src/plugins/qmlinspector/qmlinspectormode.cpp
@@ -75,6 +75,8 @@
 #include <QtGui/qlabel.h>
 #include <QtGui/qspinbox.h>
 
+#include <QtNetwork/QHostAddress>
+
 
 QT_BEGIN_NAMESPACE
 
@@ -156,17 +158,11 @@ QmlInspectorMode::QmlInspectorMode(QObject *parent)
 {    
     m_watchTableModel = new WatchTableModel(0, this);
 
-    initActions();
     setWidget(createModeWindow());
 
     setName(tr("QML Inspect"));
     setIcon(QIcon(":/qmlinspector/images/logo.png"));
-    setUniqueModeName("QML_INSPECT_MODE");    
-}
-
-quint16 QmlInspectorMode::viewerPort() const
-{
-    return m_portSpinBox->value();
+    setUniqueModeName("QML_INSPECT_MODE");
 }
 
 void QmlInspectorMode::connectToViewer()
@@ -181,12 +177,30 @@ void QmlInspectorMode::connectToViewer()
         delete m_conn;
     }
 
+    ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::instance()->currentProject();
+    if (!project) {
+        emit statusMessage(tr("No active project, debugging canceled."));
+        return;
+    }
+
+    ProjectExplorer::RunConfiguration* config = project->activeRunConfiguration();
+    if (!config) {
+        emit statusMessage(tr("Cannot find project run configuration, debugging canceled."));
+        return;
+    }
+
+    // TODO load from QmlProject settings!!
+    QHostAddress host = QHostAddress::LocalHost;
+    quint16 port = 3768;
+
     m_conn = new QmlDebugConnection(this);
     connect(m_conn, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
             SLOT(connectionStateChanged()));
     connect(m_conn, SIGNAL(error(QAbstractSocket::SocketError)),
             SLOT(connectionError()));
-    m_conn->connectToHost(m_addressEdit->text(), m_portSpinBox->value());
+
+    emit statusMessage(tr("[Inspector] set to connect to debug server %1:%2").arg(host.toString()).arg(port));
+    m_conn->connectToHost(host, port);
 }
 
 void QmlInspectorMode::disconnectFromViewer()
@@ -201,8 +215,6 @@ void QmlInspectorMode::connectionStateChanged()
         case QAbstractSocket::UnconnectedState:
         {
             emit statusMessage(tr("[Inspector] disconnected.\n\n"));
-            m_addressEdit->setEnabled(true);
-            m_portSpinBox->setEnabled(true);
 
             delete m_engineQuery;
             m_engineQuery = 0;
@@ -219,8 +231,6 @@ void QmlInspectorMode::connectionStateChanged()
         case QAbstractSocket::ConnectedState:
         {
             emit statusMessage(tr("[Inspector] connected.\n"));
-            m_addressEdit->setEnabled(false);
-            m_portSpinBox->setEnabled(false);
 
             if (!m_client) {
                 m_client = new QmlEngineDebug(m_conn, this);
@@ -251,29 +261,6 @@ void QmlInspectorMode::connectionError()
             .arg(m_conn->error()).arg(m_conn->errorString()));
 }
 
-void QmlInspectorMode::initActions()
-{
-    m_actions.startAction = new QAction(tr("Start Inspector"), this);
-    m_actions.startAction->setIcon(QIcon(ProjectExplorer::Constants::ICON_RUN));
-    
-    m_actions.stopAction = new QAction(tr("Stop Inspector"), this);
-    m_actions.stopAction->setIcon(QIcon(ProjectExplorer::Constants::ICON_STOP));
-
-    Core::ICore *core = Core::ICore::instance();
-    Core::ActionManager *am = core->actionManager();
-    Core::UniqueIDManager *uidm = core->uniqueIDManager();
-
-    QList<int> context;
-    context << uidm->uniqueIdentifier(QmlInspector::Constants::C_INSPECTOR);
-
-    am->registerAction(m_actions.startAction, QmlInspector::Constants::RUN, context);
-    connect(m_actions.startAction, SIGNAL(triggered()), SIGNAL(startViewer()));
-    
-    am->registerAction(m_actions.stopAction, QmlInspector::Constants::STOP, context);
-    connect(m_actions.stopAction, SIGNAL(triggered()), SIGNAL(stopViewer()));
-}    
-
-
 QToolButton *QmlInspectorMode::createToolButton(QAction *action)
 {
     QToolButton *button = new QToolButton;
@@ -329,10 +316,9 @@ QWidget *QmlInspectorMode::createMainView()
     
     Core::ICore *core = Core::ICore::instance();
     Core::ActionManager *am = core->actionManager();    
-    configBarLayout->addWidget(createToolButton(am->command(QmlInspector::Constants::RUN)->action()));
-    configBarLayout->addWidget(createToolButton(am->command(QmlInspector::Constants::STOP)->action()));
-    configBarLayout->addWidget(m_addressEdit);
-    configBarLayout->addWidget(m_portSpinBox);
+    configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::DEBUG)->action()));
+    configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::STOP)->action()));
+
     configBarLayout->addStretch();
        
     QWidget *widgetAboveTabs = new QWidget;
@@ -450,15 +436,6 @@ void QmlInspectorMode::initWidgets()
     connect(m_objectTreeWidget, SIGNAL(currentObjectChanged(QmlDebugObjectReference)),
             m_expressionWidget, SLOT(setCurrentObject(QmlDebugObjectReference)));
 
-    m_addressEdit = new QLineEdit;
-    m_addressEdit->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
-    m_addressEdit->setText("127.0.0.1");
-
-    m_portSpinBox = new QSpinBox;
-    m_portSpinBox->setMinimum(1024);
-    m_portSpinBox->setMaximum(20000);
-    m_portSpinBox->setValue(3768);
-
     m_engineSpinBox = new EngineSpinBox;
     m_engineSpinBox->setEnabled(false);
     connect(m_engineSpinBox, SIGNAL(valueChanged(int)),
diff --git a/src/plugins/qmlinspector/qmlinspectormode.h b/src/plugins/qmlinspector/qmlinspectormode.h
index 00f136dba2e625dd985d14ed08bfe53a9db3203c..764fde4ba3c8108cf4362ba4a95172bd097ee567 100644
--- a/src/plugins/qmlinspector/qmlinspectormode.h
+++ b/src/plugins/qmlinspector/qmlinspectormode.h
@@ -62,12 +62,7 @@ class QmlInspectorMode : public Core::BaseMode
 public:
     QmlInspectorMode(QObject *parent = 0);
     
-    
-    quint16 viewerPort() const;
-    
 signals:
-    void startViewer();
-    void stopViewer();
     void statusMessage(const QString &text);
     
 public slots: 
@@ -84,20 +79,12 @@ private slots:
     void treeObjectActivated(const QmlDebugObjectReference &obj);
 
 private:
-    struct Actions {
-        QAction *startAction;
-        QAction *stopAction;
-    };
-    
-    void initActions();
     QWidget *createModeWindow();
     QWidget *createMainView();
     void initWidgets();
     QWidget *createBottomWindow();
     QToolButton *createToolButton(QAction *action);
     
-    Actions m_actions;
-    
     QmlDebugConnection *m_conn;
     QmlEngineDebug *m_client;
 
@@ -111,8 +98,6 @@ private:
     CanvasFrameRate *m_frameRateWidget;
     ExpressionQueryWidget *m_expressionWidget;
 
-    QLineEdit *m_addressEdit;
-    QSpinBox *m_portSpinBox;
     EngineSpinBox *m_engineSpinBox;
 };
 
diff --git a/src/plugins/qmlinspector/qmlinspectorplugin.cpp b/src/plugins/qmlinspector/qmlinspectorplugin.cpp
index a81184b379fe3d434e2c7d48c8ed27c44615a230..2ca3f0c54166fb4985a2d131a6968e5a7f6852df 100644
--- a/src/plugins/qmlinspector/qmlinspectorplugin.cpp
+++ b/src/plugins/qmlinspector/qmlinspectorplugin.cpp
@@ -26,7 +26,6 @@
 ** contact the sales department at http://qt.nokia.com/contact.
 **
 **************************************************************************/
-#include "runcontrol.h"
 #include "qmlinspector.h"
 #include "qmlinspectormode.h"
 #include "inspectoroutputpane.h"
@@ -36,6 +35,7 @@
 #include <private/qmldebugclient_p.h>
 
 #include <coreplugin/icore.h>
+#include <coreplugin/modemanager.h>
 
 #include <projectexplorer/runconfiguration.h>
 #include <projectexplorer/projectexplorer.h>
@@ -55,8 +55,7 @@ QT_BEGIN_NAMESPACE
 
 
 QmlInspectorPlugin::QmlInspectorPlugin()
-    : m_inspectMode(0),
-      m_runControl(0)
+    : m_inspectMode(0)
 {
 }
 
@@ -89,8 +88,6 @@ bool QmlInspectorPlugin::initialize(const QStringList &arguments, QString *error
     context.append(uidm->uniqueIdentifier(Core::Constants::C_NAVIGATION_PANE));
 
     m_inspectMode = new QmlInspectorMode(this);
-    connect(m_inspectMode, SIGNAL(startViewer()), SLOT(startViewer()));
-    connect(m_inspectMode, SIGNAL(stopViewer()), SLOT(stopViewer()));
     m_inspectMode->setContext(context);
     addObject(m_inspectMode);
 
@@ -100,9 +97,9 @@ bool QmlInspectorPlugin::initialize(const QStringList &arguments, QString *error
     connect(m_inspectMode, SIGNAL(statusMessage(QString)),
             m_outputPane, SLOT(addInspectorStatus(QString)));
 
-    m_runControlFactory = new QmlInspectorRunControlFactory(this);
-    addAutoReleasedObject(m_runControlFactory);
-    
+    connect(core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*)),
+            SLOT(currentModeChanged(Core::IMode*)));
+
     return true;
 }
 
@@ -110,50 +107,10 @@ void QmlInspectorPlugin::extensionsInitialized()
 {
 }
 
-void QmlInspectorPlugin::startViewer()
-{
-    stopViewer();
-    
-    ProjectExplorer::Project *project = 0;
-    ProjectExplorer::ProjectExplorerPlugin *plugin = ProjectExplorer::ProjectExplorerPlugin::instance();
-    if (plugin)
-        project = plugin->currentProject();
-    if (!project) {
-        qDebug() << "No project loaded"; // TODO should this just run the debugger without a viewer?
-        return;
-    }
-        
-    ProjectExplorer::RunConfiguration *rc = project->activeRunConfiguration();
-
-    QmlInspector::StartParameters sp;
-    sp.port = m_inspectMode->viewerPort();
-
-    m_runControl = m_runControlFactory->create(rc, ProjectExplorer::Constants::RUNMODE, sp);
-
-    if (m_runControl) {
-        connect(m_runControl, SIGNAL(started()), m_inspectMode, SLOT(connectToViewer()));
-        connect(m_runControl, SIGNAL(finished()), m_inspectMode, SLOT(disconnectFromViewer()));
-
-        connect(m_runControl, SIGNAL(addToOutputWindow(RunControl*,QString)),
-                m_outputPane, SLOT(addOutput(RunControl*,QString)));
-        connect(m_runControl, SIGNAL(addToOutputWindowInline(RunControl*,QString)),
-                m_outputPane, SLOT(addOutputInline(RunControl*,QString)));
-        connect(m_runControl, SIGNAL(error(RunControl*,QString)),
-                m_outputPane, SLOT(addErrorOutput(RunControl*,QString)));
- 
-        m_runControl->start();
-        m_outputPane->popup(false);
-    }
-    
-}
-
-void QmlInspectorPlugin::stopViewer()
+void QmlInspectorPlugin::currentModeChanged(Core::IMode *mode)
 {
-    if (m_runControl) {
-        m_runControl->stop();
-        m_runControl->deleteLater();
-        m_runControl = 0;
-    }
+    if (mode == m_inspectMode) 
+        m_inspectMode->connectToViewer();
 }
 
 
diff --git a/src/plugins/qmlinspector/qmlinspectorplugin.h b/src/plugins/qmlinspector/qmlinspectorplugin.h
index a1735d4c3bfdb578483ba9a7ff55b22b8c7b5c97..ccec2f9b7c5d2c3ab9b955d6f9083c7ac8e5f688 100644
--- a/src/plugins/qmlinspector/qmlinspectorplugin.h
+++ b/src/plugins/qmlinspector/qmlinspectorplugin.h
@@ -38,14 +38,12 @@ QT_BEGIN_NAMESPACE
 
 class QStringList;
 
-
-class QmlInspectorRunControlFactory;
 class QmlInspectorMode;
 class InspectorOutputPane;
 
-namespace ProjectExplorer
+namespace Core
 {
-    class RunControl;
+    class IMode;
 }
 
 class QmlInspectorPlugin : public ExtensionSystem::IPlugin
@@ -61,15 +59,11 @@ public:
     virtual void shutdown();
 
 private slots:
-    void startViewer();
-    void stopViewer();
+    void currentModeChanged(Core::IMode *mode);
 
 private:
     QmlInspectorMode *m_inspectMode;
     InspectorOutputPane *m_outputPane;
-    
-    QmlInspectorRunControlFactory *m_runControlFactory;
-    QPointer<ProjectExplorer::RunControl> m_runControl;
 };
 
 
diff --git a/src/plugins/qmlinspector/runcontrol.cpp b/src/plugins/qmlinspector/runcontrol.cpp
deleted file mode 100644
index 722543105941bf4eae95fd6b13c3cb0c731c3764..0000000000000000000000000000000000000000
--- a/src/plugins/qmlinspector/runcontrol.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/**************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** Commercial Usage
-**
-** Licensees holding valid Qt Commercial licenses may use this file in
-** accordance with the Qt Commercial License Agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Nokia.
-**
-** GNU Lesser General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
-**
-**************************************************************************/
-#include "runcontrol.h"
-
-#include <projectexplorer/applicationlauncher.h>
-#include <projectexplorer/applicationrunconfiguration.h>
-#include <projectexplorer/projectexplorerconstants.h>
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qtimer.h>
-
-using namespace ProjectExplorer;
-
-
-QmlInspectorRunControlFactory::QmlInspectorRunControlFactory(QObject *parent)
-    : ProjectExplorer::IRunControlFactory(parent)
-{
-}
-
-bool QmlInspectorRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const
-{
-    Q_UNUSED(runConfiguration);
-    if (mode != ProjectExplorer::Constants::RUNMODE)
-        return false;
-    return true;
-}
-
-ProjectExplorer::RunControl *QmlInspectorRunControlFactory::create(RunConfiguration *runConfiguration, const QString &mode)
-{
-    Q_UNUSED(mode);
-    return new QmlInspectorRunControl(runConfiguration);
-}
-
-ProjectExplorer::RunControl *QmlInspectorRunControlFactory::create(ProjectExplorer::RunConfiguration *runConfiguration,
-const QString &mode, const QmlInspector::StartParameters &sp)
-{
-    Q_UNUSED(mode);
-    return new QmlInspectorRunControl(runConfiguration, sp);
-}
-                
-QString QmlInspectorRunControlFactory::displayName() const
-{
-    return tr("Qml Inspector");
-}
-
-QWidget *QmlInspectorRunControlFactory::configurationWidget(RunConfiguration *runConfiguration)
-{
-    Q_UNUSED(runConfiguration);
-    return 0;
-}
-
-
-
-QmlInspectorRunControl::QmlInspectorRunControl(ProjectExplorer::RunConfiguration *runConfiguration,
-const QmlInspector::StartParameters &sp)
-    : ProjectExplorer::RunControl(runConfiguration),
-      m_configuration(runConfiguration),
-      m_running(false),
-      m_viewerLauncher(0),
-      m_startParams(sp)
-{
-}
-
-QmlInspectorRunControl::~QmlInspectorRunControl()
-{
-}
-
-void QmlInspectorRunControl::start()
-{
-    if (m_running || m_viewerLauncher)
-        return;
-
-    m_viewerLauncher = new ProjectExplorer::ApplicationLauncher(this);
-    connect(m_viewerLauncher, SIGNAL(applicationError(QString)), SLOT(applicationError(QString)));
-    connect(m_viewerLauncher, SIGNAL(processExited(int)), SLOT(viewerExited()));
-    connect(m_viewerLauncher, SIGNAL(appendOutput(QString)), SLOT(appendOutput(QString)));
-    connect(m_viewerLauncher, SIGNAL(bringToForegroundRequested(qint64)),
-            this, SLOT(appStarted()));
-
-    LocalApplicationRunConfiguration *rc = qobject_cast<LocalApplicationRunConfiguration *>(m_configuration);
-    if (!rc)
-        return;
-
-    ProjectExplorer::Environment env = rc->environment();
-    env.set("QML_DEBUG_SERVER_PORT", QString::number(m_startParams.port));
-
-    QStringList arguments = rc->commandLineArguments();
-    arguments << QLatin1String("-stayontop");
-
-    m_viewerLauncher->setEnvironment(env.toStringList());
-    m_viewerLauncher->setWorkingDirectory(rc->workingDirectory());
-
-    m_running = true;
-
-    m_viewerLauncher->start(static_cast<ApplicationLauncher::Mode>(rc->runMode()),
-                            rc->executable(), arguments);
-}
-
-void QmlInspectorRunControl::stop()
-{
-    if (m_viewerLauncher->isRunning())
-        m_viewerLauncher->stop();
-}
-
-bool QmlInspectorRunControl::isRunning() const
-{
-    return m_running;
-}
-
-void QmlInspectorRunControl::appStarted()
-{
-    QTimer::singleShot(500, this, SLOT(delayedStart()));
-}
-
-void QmlInspectorRunControl::appendOutput(const QString &s)
-{
-    emit addToOutputWindow(this, s);
-}
-
-void QmlInspectorRunControl::delayedStart()
-{
-    emit started();
-}
-
-void QmlInspectorRunControl::viewerExited()
-{
-    m_running = false;
-    emit finished();
-    
-    deleteLater();
-}
-
-void QmlInspectorRunControl::applicationError(const QString &s)
-{
-    emit error(this, s);
-}
diff --git a/src/plugins/qmlinspector/runcontrol.h b/src/plugins/qmlinspector/runcontrol.h
deleted file mode 100644
index b2523b5347aee9cfab81e52fb88325de98d7a473..0000000000000000000000000000000000000000
--- a/src/plugins/qmlinspector/runcontrol.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/**************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** Commercial Usage
-**
-** Licensees holding valid Qt Commercial licenses may use this file in
-** accordance with the Qt Commercial License Agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Nokia.
-**
-** GNU Lesser General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
-**
-**************************************************************************/
-#ifndef QMLINSPECTORRUNCONTROL_H
-#define QMLINSPECTORRUNCONTROL_H
-
-#include "qmlinspector.h"
-
-#include <projectexplorer/runconfiguration.h>
-
-#include <QtCore/qobject.h>
-
-namespace ProjectExplorer {
-    class ApplicationLauncher;
-}
-
-class QmlInspectorRunControlFactory : public ProjectExplorer::IRunControlFactory
-{
-    Q_OBJECT
-
-public:
-    explicit QmlInspectorRunControlFactory(QObject *parent);
-
-    virtual bool canRun(
-                ProjectExplorer::RunConfiguration *runConfiguration,
-                const QString &mode) const;
-
-    virtual ProjectExplorer::RunControl *create(
-                ProjectExplorer::RunConfiguration *runConfiguration,
-                const QString &mode);
-
-    ProjectExplorer::RunControl *create(
-                ProjectExplorer::RunConfiguration *runConfiguration,
-                const QString &mode,
-                const QmlInspector::StartParameters &sp);
-                
-    virtual QString displayName() const;
-
-    virtual QWidget *configurationWidget(ProjectExplorer::RunConfiguration *runConfiguration);
-};
-
-class QmlInspectorRunControl : public ProjectExplorer::RunControl
-{
-    Q_OBJECT
-
-public:
-    explicit QmlInspectorRunControl(ProjectExplorer::RunConfiguration *runConfiguration,
-                                    const QmlInspector::StartParameters &sp = QmlInspector::StartParameters());
-    ~QmlInspectorRunControl();
-    
-    virtual void start();
-    virtual void stop();
-    virtual bool isRunning() const;
-
-private slots:
-    void appendOutput(const QString &s);
-    void appStarted();
-    void delayedStart();
-    void viewerExited();
-    void applicationError(const QString &error);
-
-private:
-    ProjectExplorer::RunConfiguration *m_configuration;
-    bool m_running;
-    ProjectExplorer::ApplicationLauncher *m_viewerLauncher;
-    QmlInspector::StartParameters m_startParams;
-};
-
-#endif
diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp
index 1efd5af8d9341c6326a18e7149cea6408947fdf2..8725e4fb788fe3e064b7b31197c4a735f3208c29 100644
--- a/src/plugins/qmlprojectmanager/qmlproject.cpp
+++ b/src/plugins/qmlprojectmanager/qmlproject.cpp
@@ -39,6 +39,7 @@
 #include <coreplugin/icore.h>
 #include <coreplugin/editormanager/editormanager.h>
 #include <coreplugin/editormanager/ieditor.h>
+#include <coreplugin/modemanager.h>
 
 #include <qmleditor/qmlmodelmanagerinterface.h>
 
@@ -59,6 +60,7 @@
 #include <QtGui/QLabel>
 #include <QtGui/QSpinBox>
 
+
 using namespace QmlProjectManager;
 using namespace QmlProjectManager::Internal;
 using namespace ProjectExplorer;
@@ -508,7 +510,7 @@ ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::create(ProjectExp
 }
 
 QmlRunControl::QmlRunControl(QmlRunConfiguration *runConfiguration, bool debugMode)
-    : RunControl(runConfiguration)
+    : RunControl(runConfiguration), m_debugMode(debugMode)
 {
     Environment environment = ProjectExplorer::Environment::systemEnvironment();
     if (debugMode)
@@ -527,7 +529,7 @@ QmlRunControl::QmlRunControl(QmlRunConfiguration *runConfiguration, bool debugMo
     connect(&m_applicationLauncher, SIGNAL(processExited(int)),
             this, SLOT(processExited(int)));
     connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
-            this, SLOT(bringApplicationToForeground(qint64)));
+            this, SLOT(slotBringApplicationToForeground(qint64)));
 }
 
 QmlRunControl::~QmlRunControl()
@@ -551,6 +553,16 @@ bool QmlRunControl::isRunning() const
     return m_applicationLauncher.isRunning();
 }
 
+void QmlRunControl::slotBringApplicationToForeground(qint64 pid)
+{
+    if (m_debugMode) {
+        Core::ICore *core = Core::ICore::instance();
+        core->modeManager()->activateMode(QLatin1String("QML_INSPECT_MODE"));
+    }
+
+    bringApplicationToForeground(pid);
+}
+
 void QmlRunControl::slotError(const QString &err)
 {
     emit error(this, err);
diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h
index 5c89239dcca428a9438f5afdf60db01ad8a5199d..454981b9d53009a337281a2f48f7a3616e8baaae 100644
--- a/src/plugins/qmlprojectmanager/qmlproject.h
+++ b/src/plugins/qmlprojectmanager/qmlproject.h
@@ -209,6 +209,7 @@ public:
 
 private slots:
     void processExited(int exitCode);
+    void slotBringApplicationToForeground(qint64 pid);
     void slotAddToOutputWindow(const QString &line);
     void slotError(const QString & error);
 
@@ -217,6 +218,7 @@ private:
 
     QString m_executable;
     QStringList m_commandLineArguments;
+    bool m_debugMode;
 };
 
 class QmlRunControlFactory : public ProjectExplorer::IRunControlFactory {