summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-11-03 08:56:33 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-09 19:51:49 +0000
commitf7227a7fcabfe17260ccbb6610b1a105844c341f (patch)
treec82b0f63daee0a3b70dc7ecabae0cb6fc452d900 /src
parent6fa74fcaf147f9904e4712fcd6521c02d89969f0 (diff)
QDomDocument::setContent: Open device if necessary
This restores the Qt 5 behavior in Qt 6, but prepares for disabling it in Qt 7. We want to deprecate the current behavior, as it makes it unclear who is responsible for calling close. Fixes: QTBUG-97747 Change-Id: I2c99eb96667e784576d8850085068ca334d75b16 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit a4ce85f356b78401fe727a07b908a1e7b5a25198) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/xml/dom/qdom.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp
index 2ac4c69b7f..603704f916 100644
--- a/src/xml/dom/qdom.cpp
+++ b/src/xml/dom/qdom.cpp
@@ -6197,12 +6197,28 @@ bool QDomDocument::setContent(const QByteArray &data, bool namespaceProcessing,
This function reads the XML document from the IO device \a dev, returning
true if the content was successfully parsed; otherwise returns \c false.
+
+ \note This method will try to open \a dev in read-only mode if it is not
+ already open. In that case, the caller is responsible for calling close.
+ This will change in Qt 7, which will no longer open \a dev. Applications
+ shoul therefore open the device themselves before calling setContent.
*/
bool QDomDocument::setContent(QIODevice* dev, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
{
if (!impl)
impl = new QDomDocumentPrivate();
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+ if (!dev->isOpen()) {
+ qWarning("QDomDocument called with unopened QIODevice. "
+ "This will not be supported in future Qt versions");
+ if (!dev->open(QIODevice::ReadOnly)) {
+ qWarning("QDomDocument::setContent: Failed to open device");
+ return false;
+ }
+ }
+#endif
+
QXmlStreamReader streamReader(dev);
streamReader.setNamespaceProcessing(namespaceProcessing);
return IMPL->setContent(&streamReader, namespaceProcessing, errorMsg, errorLine, errorColumn);