diff options
author | Denis Klychkov <kd.snake@gmail.com> | 2016-11-25 23:25:53 +0300 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2016-11-28 20:03:27 +0000 |
commit | c6e31fc743eb7dd4bda5eae502c5ebfda59d8b3d (patch) | |
tree | 3ad4f60181b78cc087a5352aca48c3ca62506f0d | |
parent | 5c1183aa377ae8de487d5541360369ebd2ee0f6b (diff) |
Accurate handling of Qt.core.resourcePrefix
Previously the value of this property was taken only from the first
input. That value became the only prefix for the whole qrc file.
Now every unique value of resourcePrefix generates new <qresource> tag
with the corresponding prefix.
Change-Id: I2177b3bc38085014c41107225bcb4bd4c51ba58b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
5 files changed, 34 insertions, 12 deletions
diff --git a/doc/reference/modules/qt-modules.qdoc b/doc/reference/modules/qt-modules.qdoc index 7d9a7e47b..5e40e7107 100644 --- a/doc/reference/modules/qt-modules.qdoc +++ b/doc/reference/modules/qt-modules.qdoc @@ -345,8 +345,7 @@ \li \c{string} \li \c{"/"} \li For files tagged as \c{qt.core.resource_data}, this property determines the prefix - under which they will be available in the generated \c qrc file. The value of this - property needs to be the same for all such files in a product. + under which they will be available in the generated \c qrc file. \row \li staticBuild \li \c{bool} diff --git a/src/lib/qtprofilesetup/templates/core.qbs b/src/lib/qtprofilesetup/templates/core.qbs index ba84ead91..98b3d3b3a 100644 --- a/src/lib/qtprofilesetup/templates/core.qbs +++ b/src/lib/qtprofilesetup/templates/core.qbs @@ -293,18 +293,29 @@ Module { try { qrcFile.writeLine('<!DOCTYPE RCC>'); qrcFile.writeLine('<RCC version="1.0">'); - var prefix = inputs["qt.core.resource_data"][0].moduleProperty("Qt.core", - "resourcePrefix"); - qrcFile.writeLine('<qresource prefix ="' + prefix + '">'); + + var inputsByPrefix = {} for (var i = 0; i < inputs["qt.core.resource_data"].length; ++i) { var inp = inputs["qt.core.resource_data"][i]; - var fullResPath = inp.filePath; - var baseDir = inp.moduleProperty("Qt.core", "resourceSourceBase"); - var relResPath = FileInfo.relativePath(baseDir, fullResPath); - qrcFile.writeLine('<file alias = "' + relResPath + '">' - + fullResPath + '</file>'); + var prefix = inp.moduleProperty("Qt.core", "resourcePrefix"); + var inputsList = inputsByPrefix[prefix] || []; + inputsList.push(inp); + inputsByPrefix[prefix] = inputsList; + } + + for (var prefix in inputsByPrefix) { + qrcFile.writeLine('<qresource prefix="' + prefix + '">'); + for (var i = 0; i < inputsByPrefix[prefix].length; ++i) { + var inp = inputsByPrefix[prefix][i]; + var fullResPath = inp.filePath; + var baseDir = inp.moduleProperty("Qt.core", "resourceSourceBase"); + var relResPath = FileInfo.relativePath(baseDir, fullResPath); + qrcFile.writeLine('<file alias = "' + relResPath + '">' + + fullResPath + '</file>'); + } + qrcFile.writeLine('</qresource>'); } - qrcFile.writeLine('</qresource>'); + qrcFile.writeLine('</RCC>'); } finally { qrcFile.close(); diff --git a/tests/auto/blackbox/testdata/auto-qrc/auto-qrc.qbs b/tests/auto/blackbox/testdata/auto-qrc/auto-qrc.qbs index 2d0452d49..3055e51b8 100644 --- a/tests/auto/blackbox/testdata/auto-qrc/auto-qrc.qbs +++ b/tests/auto/blackbox/testdata/auto-qrc/auto-qrc.qbs @@ -20,6 +20,14 @@ Project { Qt.core.resourceSourceBase: "qrc-base/subdir" files: ["resource2.txt"] + + Group { + prefix: "qrc-base/subdir/" + + Qt.core.resourcePrefix: "/theOtherPrefix" + + files: ["resource3.txt"] + } } } } diff --git a/tests/auto/blackbox/testdata/auto-qrc/main.cpp b/tests/auto/blackbox/testdata/auto-qrc/main.cpp index bbfcd8fee..53a33854d 100644 --- a/tests/auto/blackbox/testdata/auto-qrc/main.cpp +++ b/tests/auto/blackbox/testdata/auto-qrc/main.cpp @@ -10,6 +10,9 @@ int main() QFile resource2(":/thePrefix/resource2.txt"); if (!resource2.open(QIODevice::ReadOnly)) return 2; + QFile resource3(":/theOtherPrefix/resource3.txt"); + if (!resource3.open(QIODevice::ReadOnly)) + return 3; std::cout << "resource data: " << resource1.readAll().constData() - << resource2.readAll().constData() << std::endl; + << resource2.readAll().constData() << resource3.readAll().constData() << std::endl; } diff --git a/tests/auto/blackbox/testdata/auto-qrc/qrc-base/subdir/resource3.txt b/tests/auto/blackbox/testdata/auto-qrc/qrc-base/subdir/resource3.txt new file mode 100644 index 000000000..6df9761da --- /dev/null +++ b/tests/auto/blackbox/testdata/auto-qrc/qrc-base/subdir/resource3.txt @@ -0,0 +1 @@ +resource3 |