qmake: Make resource file contents available again

The Qml code model needs the contents of resource files. This was done using
QmakeVfs::readVirtualFile, which is not correct, since it does not read data
from files on disk. So fix this mistake by using QmakeVfs::readFile instead.

Task-number: QTCREATORBUG-18140
Change-Id: I25fd07d63ab02764bdf3fa705e2ff025d6831581
Reviewed-by: Marco Benelli <marco.benelli@qt.io>
This commit is contained in:
Tobias Hunger
2017-05-02 12:36:04 +02:00
parent ae1ae27be3
commit ec0ff0cf7c
2 changed files with 7 additions and 6 deletions

View File

@@ -162,14 +162,14 @@ static void createTree(const QmakePriFile *pri, QmakePriFileNode *node)
for (const FileName &file : newFilePaths) { for (const FileName &file : newFilePaths) {
auto vfs = pri->project()->qmakeVfs(); auto vfs = pri->project()->qmakeVfs();
QString contents; QString contents;
QString errorMessage;
// Prefer the cumulative file if it's non-empty, based on the assumption // Prefer the cumulative file if it's non-empty, based on the assumption
// that it contains more "stuff". // that it contains more "stuff".
vfs->readVirtualFile(file.toString(), QMakeVfs::VfsCumulative, &contents); vfs->readFile(file.toString(), QMakeVfs::VfsCumulative, &contents, &errorMessage);
// If the cumulative evaluation botched the file too much, try the exact one. // If the cumulative evaluation botched the file too much, try the exact one.
if (contents.isEmpty()) if (contents.isEmpty())
vfs->readVirtualFile(file.toString(), QMakeVfs::VfsExact, &contents); vfs->readFile(file.toString(), QMakeVfs::VfsExact, &contents, &errorMessage);
auto resourceNode auto resourceNode = new ResourceEditor::ResourceTopLevelNode(file, false, contents, vfolder);
= new ResourceEditor::ResourceTopLevelNode(file, false, contents, vfolder);
vfolder->addNode(resourceNode); vfolder->addNode(resourceNode);
} }
} else { } else {

View File

@@ -358,14 +358,15 @@ void QmakeProject::updateQmlJSCodeModel()
projectInfo.activeResourceFiles.append(exactResources); projectInfo.activeResourceFiles.append(exactResources);
projectInfo.allResourceFiles.append(exactResources); projectInfo.allResourceFiles.append(exactResources);
projectInfo.allResourceFiles.append(cumulativeResources); projectInfo.allResourceFiles.append(cumulativeResources);
QString errorMessage;
foreach (const QString &rc, exactResources) { foreach (const QString &rc, exactResources) {
QString contents; QString contents;
if (m_qmakeVfs->readVirtualFile(rc, QMakeVfs::VfsExact, &contents)) if (m_qmakeVfs->readFile(rc, QMakeVfs::VfsExact, &contents, &errorMessage) == QMakeVfs::ReadOk)
projectInfo.resourceFileContents[rc] = contents; projectInfo.resourceFileContents[rc] = contents;
} }
foreach (const QString &rc, cumulativeResources) { foreach (const QString &rc, cumulativeResources) {
QString contents; QString contents;
if (m_qmakeVfs->readVirtualFile(rc, QMakeVfs::VfsCumulative, &contents)) if (m_qmakeVfs->readFile(rc, QMakeVfs::VfsCumulative, &contents, &errorMessage) == QMakeVfs::ReadOk)
projectInfo.resourceFileContents[rc] = contents; projectInfo.resourceFileContents[rc] = contents;
} }
if (!hasQmlLib) { if (!hasQmlLib) {