diff --git a/src/xmpp/xmpp-im/xmpp_vcard4.cpp b/src/xmpp/xmpp-im/xmpp_vcard4.cpp index 0a2ea0f9..2542b025 100644 --- a/src/xmpp/xmpp-im/xmpp_vcard4.cpp +++ b/src/xmpp/xmpp-im/xmpp_vcard4.cpp @@ -715,29 +715,29 @@ VCard VCard::fromFile(const QString &filename) if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return VCard(); - return fromFile(file); + auto vcard = fromDevice(&file); + file.close(); + return vcard; } -VCard VCard::fromFile(QFile &file) +VCard VCard::fromDevice(QIODevice *dev) { QDomDocument doc; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - if (!doc.setContent(&file, true)) { + if (!doc.setContent(dev, true)) { #else - if (!doc.setContent(&file, QDomDocument::ParseOption::UseNamespaceProcessing)) { + if (!doc.setContent(dev, QDomDocument::ParseOption::UseNamespaceProcessing)) { #endif - file.close(); - return VCard(); + return {}; } - file.close(); QDomElement root = doc.documentElement(); if (root.tagName() != QLatin1String("vcards") || root.namespaceURI() != VCARD_NAMESPACE) - return VCard(); + return {}; QDomElement vCardElement = root.firstChildElement(QLatin1String("vcard")); if (vCardElement.isNull()) - return VCard(); + return {}; return VCard(vCardElement); } diff --git a/src/xmpp/xmpp-im/xmpp_vcard4.h b/src/xmpp/xmpp-im/xmpp_vcard4.h index 9a5790ac..e4ce7d98 100644 --- a/src/xmpp/xmpp-im/xmpp_vcard4.h +++ b/src/xmpp/xmpp-im/xmpp_vcard4.h @@ -252,7 +252,7 @@ class VCard { QDomElement toXmlElement(QDomDocument &document) const; static VCard fromFile(const QString &filename); - static VCard fromFile(QFile &file); + static VCard fromDevice(QIODevice *dev); bool save(const QString &filename) const; void fromVCardTemp(const XMPP::VCard &tempVCard);