diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index c8c8b867145762f63be5bdde82f3197e3eafba43..1283699787eb01a44d3ea53fbe92513bd94c617f 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -662,7 +662,7 @@ QMap<QString, QByteArray> CppModelManager::buildWorkingCopyList()
         TextEditor::ITextEditor *textEditor = it.key();
         CppEditorSupport *editorSupport = it.value();
         QString fileName = textEditor->file()->fileName();
-        workingCopy[fileName] = editorSupport->contents().toUtf8();
+        workingCopy[fileName] = editorSupport->contents();
     }
 
     // add the project configuration file
@@ -846,12 +846,12 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
 
             QList<Editor> todo;
             foreach (const Editor &e, todo) {
-                if (e.widget != ed)
+                if (e.textEditor != textEditor)
                     todo.append(e);
             }
 
             Editor e;
-            e.widget = ed;
+            e.textEditor = textEditor;
             e.selections = selections;
             e.ifdefedOutBlocks = blockRanges;
             todo.append(e);
@@ -870,16 +870,22 @@ void CppModelManager::postEditorUpdate()
 void CppModelManager::updateEditorSelections()
 {
     foreach (const Editor &ed, m_todo) {
-        if (! ed.widget)
+        if (! ed.textEditor)
             continue;
 
-        ed.widget->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection,
-                                      ed.selections);
+        TextEditor::ITextEditor *textEditor = ed.textEditor;
+        TextEditor::BaseTextEditor *editor = qobject_cast<TextEditor::BaseTextEditor *>(textEditor->widget());
+        if (! editor)
+            continue;
+
+        editor->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection,
+                                   ed.selections);
 
-        ed.widget->setIfdefedOutBlocks(ed.ifdefedOutBlocks);
+        editor->setIfdefedOutBlocks(ed.ifdefedOutBlocks);
     }
 
     m_todo.clear();
+
 }
 
 void CppModelManager::onProjectAdded(ProjectExplorer::Project *)
diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h
index 63b414c1c05c3cfb3bbeb21cfad852527f2068c4..fc38f13b6d5dacc419a2669cbe2b93f56efffc23 100644
--- a/src/plugins/cpptools/cppmodelmanager.h
+++ b/src/plugins/cpptools/cppmodelmanager.h
@@ -167,7 +167,7 @@ private:
     mutable QMutex mutex;
 
     struct Editor {
-        QPointer<TextEditor::BaseTextEditor> widget;
+        QPointer<TextEditor::ITextEditor> textEditor;
         QList<QTextEdit::ExtraSelection> selections;
         QList<TextEditor::BaseTextEditor::BlockRange> ifdefedOutBlocks;
     };
diff --git a/src/plugins/cpptools/cpptoolseditorsupport.cpp b/src/plugins/cpptools/cpptoolseditorsupport.cpp
index 5eba9158e72ec4596c9765f2a8f6c9fa738e49af..63c926dbfaa1fd8808a4f5b354d71a98be5dd3a7 100644
--- a/src/plugins/cpptools/cpptoolseditorsupport.cpp
+++ b/src/plugins/cpptools/cpptoolseditorsupport.cpp
@@ -66,12 +66,12 @@ void CppEditorSupport::setTextEditor(TextEditor::ITextEditor *textEditor)
     updateDocument();
 }
 
-QString CppEditorSupport::contents()
+QByteArray CppEditorSupport::contents()
 {
     if (! _textEditor)
-        return QString();
+        return QByteArray();
     else if (! _cachedContents.isEmpty())
-        _cachedContents = _textEditor->contents();
+        _cachedContents = _textEditor->contents().toUtf8();
 
     return _cachedContents;
 }
@@ -96,13 +96,15 @@ void CppEditorSupport::updateDocument()
 
 void CppEditorSupport::updateDocumentNow()
 {
+    qDebug() << "*** update document now";
+
     if (_documentParser.isRunning()) {
         _updateDocumentTimer->start(_updateDocumentInterval);
     } else {
         _updateDocumentTimer->stop();
 
         QStringList sourceFiles(_textEditor->file()->fileName());
-        _cachedContents = _textEditor->contents();
+        _cachedContents = _textEditor->contents().toUtf8();
         _documentParser = _modelManager->refreshSourceFiles(sourceFiles);
     }
 }
diff --git a/src/plugins/cpptools/cpptoolseditorsupport.h b/src/plugins/cpptools/cpptoolseditorsupport.h
index ef91da43e0eb2be975afab5917c39103dc521045..4df23c7b2561e6c2de34859216d8ff02a7e4f82c 100644
--- a/src/plugins/cpptools/cpptoolseditorsupport.h
+++ b/src/plugins/cpptools/cpptoolseditorsupport.h
@@ -61,7 +61,7 @@ public:
     int updateDocumentInterval() const;
     void setUpdateDocumentInterval(int updateDocumentInterval);
 
-    QString contents();
+    QByteArray contents(); // UTF-8 encoded
 
 Q_SIGNALS:
     void contentsChanged();
@@ -78,7 +78,7 @@ private:
     QTimer *_updateDocumentTimer;
     int _updateDocumentInterval;
     QFuture<void> _documentParser;
-    QString _cachedContents;
+    QByteArray _cachedContents;
 };
 
 } // namespace Internal