summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2024-02-10 03:10:44 +0200
committerAhmad Samir <a.samirh78@gmail.com>2024-03-21 19:05:02 +0200
commit3c50ad828861bee82e53469deab28b4e286cbeda (patch)
tree36ab6a8c7f88fc7c729bdc1b958c81970b63e95c /src/corelib/doc
parent0737fca6b2f4b29b7e4eda221147187cf72f96f3 (diff)
QFileSystemEngine: make factory functions return unique_ptr<QABFE>
This makes the ownership of the returned pointer clearer. It also matches reality, some call sites were already storing the pointer in a unique_ptr. Also shorten the function name to "createLegacyEngine", you have to read its docs anyway to figure out what it does. Drive-by changes: less magic numbers; use sliced(); return nullptr instead of `0`. Change-Id: I637759b4160b28b15adf5f6548de336887338dab Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/corelib/doc')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp
index 557ff765a7..4300fc2da9 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp
@@ -1,17 +1,21 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+using namespace Qt::StringLiterals;
+
//! [0]
class ZipEngineHandler : public QAbstractFileEngineHandler
{
public:
- QAbstractFileEngine *create(const QString &fileName) const override;
+ std::unique_ptr<QAbstractFileEngine> create(const QString &fileName) const override;
};
-QAbstractFileEngine *ZipEngineHandler::create(const QString &fileName) const
+std::unique_ptr<QAbstractFileEngine> ZipEngineHandler::create(const QString &fileName) const
{
// ZipEngineHandler returns a ZipEngine for all .zip files
- return fileName.toLower().endsWith(".zip") ? new ZipEngine(fileName) : 0;
+ if (fileName.toLower().endsWith(".zip"_L1))
+ return std::make_unique<ZipEngine>(fileName);
+ return {};
}
int main(int argc, char **argv)
@@ -27,12 +31,14 @@ int main(int argc, char **argv)
}
//! [0]
-
//! [1]
-QAbstractSocketEngine *ZipEngineHandler::create(const QString &fileName) const
+std::unique_ptr<QAbstractFileEngine> ZipEngineHandler::create(const QString &fileName) const
{
// ZipEngineHandler returns a ZipEngine for all .zip files
- return fileName.toLower().endsWith(".zip") ? new ZipEngine(fileName) : 0;
+ if (fileName.toLower().endsWith(".zip"_L1))
+ return std::make_unique<ZipEngine>(fileName);
+ else
+ return {};
}
//! [1]