diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 24536b0278172d7e6ff08f7f914d80921f07eba4..6b5307a78e700d6c054a3aab0375ea6b41a7cdcb 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -1670,8 +1670,8 @@ void DebuggerPluginPrivate::attachToQmlPort()
     setConfigValue(_("LastQmlServerAddress"), dlg.host());
     setConfigValue(_("LastQmlServerPort"), dlg.port());
 
-    sp.serverAddress = dlg.host();
-    sp.serverPort = dlg.port();
+    sp.qmlServerAddress = dlg.host();
+    sp.qmlServerPort = dlg.port();
 
     sp.startMode = AttachToQmlPort;
     if (RunControl *rc = createDebugger(sp))
diff --git a/src/plugins/debugger/qml/qmladapter.cpp b/src/plugins/debugger/qml/qmladapter.cpp
index a8c928ac3d5140d8835294a8fe7fde98225a8b00..1cb8142147f76ade7936a824759549b24170beac 100644
--- a/src/plugins/debugger/qml/qmladapter.cpp
+++ b/src/plugins/debugger/qml/qmladapter.cpp
@@ -54,19 +54,15 @@ public:
     explicit QmlAdapterPrivate(DebuggerEngine *engine)
         : m_engine(engine)
         , m_qmlClient(0)
-        , m_connectionAttempts(0)
-        , m_maxConnectionAttempts(50) // overall time: 50 x 200ms
         , m_conn(0)
     {
-        m_connectionTimer.setInterval(200);
+        m_connectionTimer.setInterval(4000);
+        m_connectionTimer.setSingleShot(true);
     }
 
     QWeakPointer<DebuggerEngine> m_engine;
     QmlDebuggerClient *m_qmlClient;
-
     QTimer m_connectionTimer;
-    int m_connectionAttempts;
-    int m_maxConnectionAttempts;
     QDeclarativeDebugConnection *m_conn;
     QHash<QString, QmlDebuggerClient*> debugClients;
 };
@@ -76,7 +72,7 @@ public:
 QmlAdapter::QmlAdapter(DebuggerEngine *engine, QObject *parent)
     : QObject(parent), d(new Internal::QmlAdapterPrivate(engine))
 {
-    connect(&d->m_connectionTimer, SIGNAL(timeout()), SLOT(pollInferior()));
+    connect(&d->m_connectionTimer, SIGNAL(timeout()), SLOT(checkConnectionState()));
     d->m_conn = new QDeclarativeDebugConnection(this);
     connect(d->m_conn, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
             SLOT(connectionStateChanged()));
@@ -86,6 +82,8 @@ QmlAdapter::QmlAdapter(DebuggerEngine *engine, QObject *parent)
     ExtensionSystem::PluginManager *pluginManager =
         ExtensionSystem::PluginManager::instance();
     pluginManager->addObject(this);
+
+    createDebuggerClients();
 }
 
 QmlAdapter::~QmlAdapter()
@@ -99,38 +97,6 @@ QmlAdapter::~QmlAdapter()
 }
 
 void QmlAdapter::beginConnection()
-{
-    d->m_connectionAttempts = 0;
-    d->m_connectionTimer.start();
-}
-
-void QmlAdapter::closeConnection()
-{
-    if (d->m_connectionTimer.isActive()) {
-        d->m_connectionTimer.stop();
-    } else {
-        if (d->m_conn)
-            d->m_conn->close();
-    }
-}
-
-void QmlAdapter::pollInferior()
-{
-    ++d->m_connectionAttempts;
-
-    if (isConnected()) {
-        d->m_connectionTimer.stop();
-        d->m_connectionAttempts = 0;
-    } else if (d->m_connectionAttempts == d->m_maxConnectionAttempts) {
-        d->m_connectionTimer.stop();
-        d->m_connectionAttempts = 0;
-        emit connectionStartupFailed();
-    } else {
-        connectToViewer();
-    }
-}
-
-void QmlAdapter::connectToViewer()
 {
     if (d->m_engine.isNull()
             || (d->m_conn && d->m_conn->state() != QAbstractSocket::UnconnectedState))
@@ -147,6 +113,20 @@ void QmlAdapter::connectToViewer()
         showConnectionStatusMessage(tr("Connecting to debug server %1:%2").arg(address).arg(QString::number(port)));
         d->m_conn->connectToHost(address, port);
     }
+
+    //A timeout to check the connection state
+    d->m_connectionTimer.start();
+}
+
+void QmlAdapter::closeConnection()
+{
+    if (d->m_connectionTimer.isActive()) {
+        d->m_connectionTimer.stop();
+    } else {
+        if (d->m_conn) {
+            d->m_conn->close();
+        }
+    }
 }
 
 void QmlAdapter::connectionErrorOccurred(QAbstractSocket::SocketError socketError)
@@ -155,8 +135,12 @@ void QmlAdapter::connectionErrorOccurred(QAbstractSocket::SocketError socketErro
                                 .arg(socketError).arg(d->m_conn->errorString()));
 
     // this is only an error if we are already connected and something goes wrong.
-    if (isConnected())
+    if (isConnected()) {
         emit connectionError(socketError);
+    } else {
+        d->m_connectionTimer.stop();
+        emit connectionStartupFailed();
+    }
 }
 
 void QmlAdapter::clientStatusChanged(QDeclarativeDebugClient::Status status)
@@ -194,8 +178,7 @@ void QmlAdapter::connectionStateChanged()
     {
         showConnectionStatusMessage(tr("connected.\n"));
 
-        if (!d->m_qmlClient)
-            createDebuggerClients();
+        d->m_connectionTimer.stop();
 
         //reloadEngines();
         emit connected();
@@ -210,6 +193,14 @@ void QmlAdapter::connectionStateChanged()
     }
 }
 
+void QmlAdapter::checkConnectionState()
+{
+    if (!isConnected()) {
+        closeConnection();
+        emit connectionStartupFailed();
+    }
+}
+
 void QmlAdapter::createDebuggerClients()
 {
 
diff --git a/src/plugins/debugger/qml/qmladapter.h b/src/plugins/debugger/qml/qmladapter.h
index a9608b341d9b5ce5530aa03aaa630c04d0f4dc13..fe5b5cdf65fad918772ebebbbdeddc528baf7ba0 100644
--- a/src/plugins/debugger/qml/qmladapter.h
+++ b/src/plugins/debugger/qml/qmladapter.h
@@ -88,10 +88,9 @@ private slots:
     void connectionErrorOccurred(QAbstractSocket::SocketError socketError);
     void clientStatusChanged(QDeclarativeDebugClient::Status status);
     void connectionStateChanged();
-    void pollInferior();
+    void checkConnectionState();
 
 private:
-    void connectToViewer();
     void createDebuggerClients();
     void showConnectionStatusMessage(const QString &message);
     void showConnectionErrorMessage(const QString &message);
diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp
index a0d52354e28bb0169b2a13cebcf9d1a668e16098..2c519f30be9a9d2a40f9baa704ff1a0c168d6a8c 100644
--- a/src/plugins/debugger/qml/qmlengine.cpp
+++ b/src/plugins/debugger/qml/qmlengine.cpp
@@ -137,10 +137,14 @@ QmlEngine::QmlEngine(const DebuggerStartParameters &startParameters,
         SIGNAL(processExited(int)),
         SLOT(disconnected()));
     connect(&d->m_applicationLauncher,
-        SIGNAL(appendMessage(QString,Utils::OutputFormat)),
-        SLOT(appendMessage(QString,Utils::OutputFormat)));
+        SIGNAL(appendMessage(QString, Utils::OutputFormat)),
+        SLOT(appendMessage(QString, Utils::OutputFormat)));
+    connect(&d->m_applicationLauncher,
+            SIGNAL(processStarted()),
+            &d->m_noDebugOutputTimer,
+            SLOT(start()));
 
-// Only wait 8 seconds for the 'Waiting for connection' on application ouput, then just try to connect
+    // Only wait 8 seconds for the 'Waiting for connection' on application ouput, then just try to connect
     // (application output might be redirected / blocked)
     d->m_noDebugOutputTimer.setSingleShot(true);
     d->m_noDebugOutputTimer.setInterval(8000);
@@ -167,6 +171,9 @@ void QmlEngine::setupInferior()
         emit requestRemoteSetup();
         if (startParameters().qmlServerPort != quint16(-1))
             notifyInferiorSetupOk();
+    } if (startParameters().startMode == AttachToQmlPort) {
+            notifyInferiorSetupOk();
+
     } else {
         d->m_applicationLauncher.setEnvironment(startParameters().environment);
         d->m_applicationLauncher.setWorkingDirectory(startParameters().workingDirectory);
@@ -197,6 +204,7 @@ void QmlEngine::connectionEstablished()
 void QmlEngine::beginConnection()
 {
     d->m_noDebugOutputTimer.stop();
+    showMessage(tr("QML Debugger connecting..."), StatusBar);
     d->m_adapter.beginConnection();
 }
 
@@ -240,6 +248,9 @@ void QmlEngine::connectionError(QAbstractSocket::SocketError socketError)
 {
     if (socketError == QAbstractSocket::RemoteHostClosedError)
         showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar);
+
+    notifyInferiorSpontaneousStop();
+    notifyInferiorIll();
 }
 
 void QmlEngine::serviceConnectionError(const QString &serviceName)
@@ -333,7 +344,9 @@ void QmlEngine::runEngine()
     if (!isSlaveEngine() && startParameters().startMode != AttachToRemoteServer
             && startParameters().startMode != AttachToQmlPort)
         startApplicationLauncher();
-    d->m_noDebugOutputTimer.start();
+
+    if (startParameters().startMode == AttachToQmlPort)
+        beginConnection();
 }
 
 void QmlEngine::startApplicationLauncher()
@@ -375,7 +388,10 @@ void QmlEngine::handleRemoteSetupFailed(const QString &message)
 
 void QmlEngine::shutdownInferior()
 {
-    d->m_adapter.activeDebuggerClient()->endSession();
+    d->m_noDebugOutputTimer.stop();
+
+    if (d->m_adapter.activeDebuggerClient())
+        d->m_adapter.activeDebuggerClient()->endSession();
 
     if (isSlaveEngine()) {
         resetLocation();
@@ -409,8 +425,10 @@ void QmlEngine::setupEngine()
 void QmlEngine::continueInferior()
 {
     QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
-    logMessage(LogSend, "CONTINUE");
-    d->m_adapter.activeDebuggerClient()->continueInferior();
+    if (d->m_adapter.activeDebuggerClient()) {
+        logMessage(LogSend, "CONTINUE");
+        d->m_adapter.activeDebuggerClient()->continueInferior();
+    }
     resetLocation();
     notifyInferiorRunRequested();
     notifyInferiorRunOk();
@@ -418,15 +436,19 @@ void QmlEngine::continueInferior()
 
 void QmlEngine::interruptInferior()
 {
-    logMessage(LogSend, "INTERRUPT");
-    d->m_adapter.activeDebuggerClient()->interruptInferior();
+    if (d->m_adapter.activeDebuggerClient()) {
+        logMessage(LogSend, "INTERRUPT");
+        d->m_adapter.activeDebuggerClient()->interruptInferior();
+    }
     notifyInferiorStopOk();
 }
 
 void QmlEngine::executeStep()
 {
-    logMessage(LogSend, "STEPINTO");
-    d->m_adapter.activeDebuggerClient()->executeStep();
+    if (d->m_adapter.activeDebuggerClient()) {
+        logMessage(LogSend, "STEPINTO");
+        d->m_adapter.activeDebuggerClient()->executeStep();
+    }
     resetLocation();
     notifyInferiorRunRequested();
     notifyInferiorRunOk();
@@ -434,8 +456,10 @@ void QmlEngine::executeStep()
 
 void QmlEngine::executeStepI()
 {
-    logMessage(LogSend, "STEPINTO");
-    d->m_adapter.activeDebuggerClient()->executeStepI();
+    if (d->m_adapter.activeDebuggerClient()) {
+        logMessage(LogSend, "STEPINTO");
+        d->m_adapter.activeDebuggerClient()->executeStepI();
+    }
     resetLocation();
     notifyInferiorRunRequested();
     notifyInferiorRunOk();
@@ -443,8 +467,10 @@ void QmlEngine::executeStepI()
 
 void QmlEngine::executeStepOut()
 {
-    logMessage(LogSend, "STEPOUT");
-    d->m_adapter.activeDebuggerClient()->executeStepOut();
+    if (d->m_adapter.activeDebuggerClient()) {
+        logMessage(LogSend, "STEPOUT");
+        d->m_adapter.activeDebuggerClient()->executeStepOut();
+    }
     resetLocation();
     notifyInferiorRunRequested();
     notifyInferiorRunOk();
@@ -452,8 +478,10 @@ void QmlEngine::executeStepOut()
 
 void QmlEngine::executeNext()
 {
-    logMessage(LogSend, "STEPOVER");
-    d->m_adapter.activeDebuggerClient()->executeNext();
+    if (d->m_adapter.activeDebuggerClient()) {
+        logMessage(LogSend, "STEPOVER");
+        d->m_adapter.activeDebuggerClient()->executeNext();
+    }
     resetLocation();
     notifyInferiorRunRequested();
     notifyInferiorRunOk();
@@ -484,8 +512,10 @@ void QmlEngine::executeJumpToLine(const ContextData &data)
 
 void QmlEngine::activateFrame(int index)
 {
-    logMessage(LogSend, QString("%1 %2").arg(QString("ACTIVATE_FRAME"), QString::number(index)));
-    d->m_adapter.activeDebuggerClient()->activateFrame(index);
+    if (d->m_adapter.activeDebuggerClient()) {
+        logMessage(LogSend, QString("%1 %2").arg(QString("ACTIVATE_FRAME"), QString::number(index)));
+        d->m_adapter.activeDebuggerClient()->activateFrame(index);
+    }
     gotoLocation(stackHandler()->frames().value(index));
 }
 
@@ -660,10 +690,10 @@ void QmlEngine::assignValueInDebugger(const WatchData *data,
     const QString &expression, const QVariant &valueV)
 {
     quint64 objectId =  data->id;
-    if (objectId > 0 && !expression.isEmpty()) {
+    if (objectId > 0 && !expression.isEmpty() && d->m_adapter.activeDebuggerClient()) {
         logMessage(LogSend, QString("%1 %2 %3 %4 %5").arg(
-                             QString("SET_PROPERTY"), QString::number(objectId), QString(expression),
-                             valueV.toString()));
+                       QString("SET_PROPERTY"), QString::number(objectId), QString(expression),
+                       valueV.toString()));
         d->m_adapter.activeDebuggerClient()->assignValueInDebugger(expression.toUtf8(), objectId, expression, valueV.toString());
     }
 }
@@ -675,15 +705,16 @@ void QmlEngine::updateWatchData(const WatchData &data,
     //watchHandler()->rebuildModel();
     showStatusMessage(tr("Stopped."), 5000);
 
-    if (!data.name.isEmpty() && data.isValueNeeded()) {
-        logMessage(LogSend, QString("%1 %2 %3").arg(QString("EXEC"), QString(data.iname),
-                                                          QString(data.name)));
-         d->m_adapter.activeDebuggerClient()->updateWatchData(&data);
-    }
-
-    if (!data.name.isEmpty() && data.isChildrenNeeded()
-            && watchHandler()->isExpandedIName(data.iname)) {
-        d->m_adapter.activeDebuggerClient()->expandObject(data.iname, data.id);
+    if (!data.name.isEmpty() && d->m_adapter.activeDebuggerClient()) {
+        if (data.isValueNeeded()) {
+            logMessage(LogSend, QString("%1 %2 %3").arg(QString("EXEC"), QString(data.iname),
+                                                        QString(data.name)));
+            d->m_adapter.activeDebuggerClient()->updateWatchData(&data);
+        }
+        if (data.isChildrenNeeded()
+                && watchHandler()->isExpandedIName(data.iname)) {
+            d->m_adapter.activeDebuggerClient()->expandObject(data.iname, data.id);
+        }
     }
 
     synchronizeWatchers();
@@ -722,9 +753,11 @@ unsigned QmlEngine::debuggerCapabilities() const
 
 QString QmlEngine::toFileInProject(const QUrl &fileUrl)
 {
-    if (d->fileFinder.projectDirectory().isEmpty()) {
-        d->fileFinder.setProjectDirectory(startParameters().projectSourceDirectory);
-        d->fileFinder.setProjectFiles(startParameters().projectSourceFiles);
+    if (startParameters().startMode != AttachToQmlPort) {
+        if (d->fileFinder.projectDirectory().isEmpty()) {
+            d->fileFinder.setProjectDirectory(startParameters().projectSourceDirectory);
+            d->fileFinder.setProjectFiles(startParameters().projectSourceFiles);
+        }
     }
 
     return d->fileFinder.findFile(fileUrl);
@@ -753,9 +786,11 @@ void QmlEngine::wrongSetupMessageBoxFinished(int result)
 
 void QmlEngine::executeDebuggerCommand(const QString& command)
 {
-    logMessage(LogSend, QString("%1 %2 %3").arg(QString("EXEC"), QString("console"),
-                                                      QString(command)));
-    d->m_adapter.activeDebuggerClient()->executeDebuggerCommand(command);
+    if (d->m_adapter.activeDebuggerClient()) {
+        logMessage(LogSend, QString("%1 %2 %3").arg(QString("EXEC"), QString("console"),
+                                                          QString(command)));
+        d->m_adapter.activeDebuggerClient()->executeDebuggerCommand(command);
+    }
 }
 
 
diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp
index d45bf6a78223245729ac223d0ac8f2f120ffdd10..2fd9f2c24cf375b0e64b72f8e4ce642f6794dd7e 100644
--- a/src/plugins/qmljsinspector/qmljsinspector.cpp
+++ b/src/plugins/qmljsinspector/qmljsinspector.cpp
@@ -152,7 +152,6 @@ InspectorUi::InspectorUi(QObject *parent)
     , m_clientProxy(0)
     , m_qmlEngine(0)
     , m_debugQuery(0)
-    , m_debugProject(0)
     , m_selectionCallbackExpected(false)
     , m_cursorPositionChangedExternally(false)
 {
@@ -310,11 +309,12 @@ void InspectorUi::connected(ClientProxy *clientProxy)
         it.value()->resetInitialDoc(doc);
     }
 
-    m_debugProject = ProjectExplorer::ProjectExplorerPlugin::instance()->startupProject();
-
-    connect(m_debugProject, SIGNAL(destroyed()), SLOT(currentDebugProjectRemoved()));
-    m_projectFinder.setProjectDirectory(m_debugProject->projectDirectory());
-    m_projectFinder.setProjectFiles(m_debugProject->files(ProjectExplorer::Project::AllFiles));
+    // project is needed for matching filenames, esp. with shadow builds.
+    ProjectExplorer::Project *debugProject = ProjectExplorer::ProjectExplorerPlugin::instance()->startupProject();
+    if (debugProject) {
+        m_projectFinder.setProjectDirectory(debugProject->projectDirectory());
+        m_projectFinder.setProjectFiles(debugProject->files(ProjectExplorer::Project::AllFiles));
+    }
 
     connectSignals();
     enable();
@@ -335,7 +335,6 @@ void InspectorUi::disconnected()
     disconnectSignals();
     disable();
 
-    m_debugProject = 0;
     m_qmlEngine = 0;
     resetViews();
 
@@ -489,11 +488,6 @@ QmlJSLiveTextPreview *InspectorUi::createPreviewForEditor(Core::IEditor *newEdit
     return preview;
 }
 
-void InspectorUi::currentDebugProjectRemoved()
-{
-    m_debugProject = 0;
-}
-
 void InspectorUi::resetViews()
 {
     m_propertyInspector->clear();
diff --git a/src/plugins/qmljsinspector/qmljsinspector.h b/src/plugins/qmljsinspector/qmljsinspector.h
index 72762e363b79d51d10b298874f9d66cf5f0475e2..b38515e4ef7199bb05a51919eb35bcec679d1691 100644
--- a/src/plugins/qmljsinspector/qmljsinspector.h
+++ b/src/plugins/qmljsinspector/qmljsinspector.h
@@ -131,7 +131,6 @@ private slots:
     void disableLivePreview();
     void crumblePathElementClicked(const QVariant &data);
 
-    void currentDebugProjectRemoved();
     void updatePendingPreviewDocuments(QmlJS::Document::Ptr doc);
     void showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos);
     void debugQueryUpdated(QDeclarativeDebugQuery::State);
@@ -167,9 +166,6 @@ private:
     QHash<QString, QmlJSLiveTextPreview *> m_textPreviews;
     QmlJS::Snapshot m_loadedSnapshot; //the snapshot loaded by the viewer
 
-    // project is needed for matching filenames, esp. with shadow builds.
-    ProjectExplorer::Project *m_debugProject;
-
     QStringList m_pendingPreviewDocumentNames;
     Utils::FileInProjectFinder m_projectFinder;