Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_corelib_io_qabstractfileengine.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//! [0]
5using namespace Qt::StringLiterals;
6// ...
8{
9public:
10 std::unique_ptr<QAbstractFileEngine> create(const QString &fileName) const override;
11};
12
13std::unique_ptr<QAbstractFileEngine> ZipEngineHandler::create(const QString &fileName) const
14{
15 // ZipEngineHandler returns a ZipEngine for all .zip files
16 if (fileName.toLower().endsWith(".zip"_L1))
17 return std::make_unique<ZipEngine>(fileName);
18 return {};
19}
20
21int main(int argc, char **argv)
22{
23 QApplication app(argc, argv);
24
25 ZipEngineHandler engine;
26
27 MainWindow window;
28 window.show();
29
30 return app.exec();
31}
32//! [0]
33
34//! [1]
35std::unique_ptr<QAbstractFileEngine> ZipEngineHandler::create(const QString &fileName) const
36{
37 // ZipEngineHandler returns a ZipEngine for all .zip files
38 if (fileName.toLower().endsWith(".zip"_L1))
39 return std::make_unique<ZipEngine>(fileName);
40 else
41 return {};
42}
43//! [1]
44
45
46//! [2]
47QAbstractFileEngine::IteratorUniquePtr
48CustomFileEngine::beginEntryList(const QString &path, QDir::Filters filters,
49 const QStringList &filterNames)
50{
51 return std::make_unique<CustomFileEngineIterator>(path, filters, filterNames);
52}
53//! [2]
54
55
56//! [3]
58{
59public:
60 CustomIterator(const QString &path, const QStringList &nameFilters, QDir::Filters filters)
62 {
63 // In a real iterator, these entries are fetched from the
64 // file system based on the value of path().
65 entries << "entry1" << "entry2" << "entry3";
66 }
67
69 {
70 if (entries.isEmpty())
71 return false;
72 if (index < entries.size() - 1) {
73 ++index;
74 return true;
75 }
76 return false;
77 }
78
80 {
81 return entries.at(index);
82 }
83
84private:
85 QStringList entries;
86 int index;
87};
88//! [3]
bool advance() override
This pure virtual function advances the iterator to the next directory entry; if the operation was su...
CustomIterator(const QString &path, const QStringList &nameFilters, QDir::Filters filters)
std::unique_ptr< QAbstractFileEngine > create(const QString &fileName) const override
[0]
int main(int argc, char *argv[])
[ctor_close]