From 82d312aad608690eef8b9d4e06e2150f2ccc82ba Mon Sep 17 00:00:00 2001
From: Andre Hartmann <aha_1980@gmx.de>
Date: Sat, 29 Sep 2012 20:35:54 +0200
Subject: [PATCH] Fix encoding of non-opened include files.

The old implementation readed the file and converted the QString toUtf8,
which seems wrong. Now use Creators default encoding.

This fixes at least wrong macro offsets that leaded to highlighting
errors in Find Usages, if there were non-ASCII characters before the
macro definition.

This should also partially solve QTCREATORBUG-7122.

Change-Id: Ic4a5add5f4769bd3d5b62fc2d67598e7abf352d9
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
---
 src/plugins/cpptools/cppmodelmanager.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index d8b5eb762d1..139792736f1 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -366,9 +366,11 @@ bool CppPreprocessor::includeFile(const QString &absoluteFilePath, QString *resu
     QFile file(absoluteFilePath);
     if (file.open(QFile::ReadOnly | QFile::Text)) {
         m_included.insert(absoluteFilePath);
+        QTextCodec *defaultCodec = Core::EditorManager::instance()->defaultTextCodec();
         QTextStream stream(&file);
-        const QString contents = stream.readAll();
-        *result = contents.toUtf8();
+        stream.setCodec(defaultCodec);
+        if (result)
+            *result = stream.readAll();
         file.close();
         return true;
     }
-- 
GitLab