Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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]
5
using
namespace
Qt::StringLiterals;
6
// ...
7
class
ZipEngineHandler
:
public
QAbstractFileEngineHandler
8
{
9
public
:
10
std
::
unique_ptr
<
QAbstractFileEngine
>
create
(
const
QString &fileName)
const
override
;
11
};
12
13
std
::
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
21
int
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]
35
std
::
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]
47
QAbstractFileEngine::IteratorUniquePtr
48
CustomFileEngine::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]
57
class
CustomIterator
:
public
QAbstractFileEngineIterator
58
{
59
public
:
60
CustomIterator
(
const
QString &path,
const
QStringList &nameFilters, QDir::Filters filters)
61
:
QAbstractFileEngineIterator
(
path
,
nameFilters
,
filters
), index(0)
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
68
bool
advance
()
override
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
79
QString
currentFileName
()
override
80
{
81
return
entries.at(index);
82
}
83
84
private
:
85
QStringList entries;
86
int
index;
87
};
88
//! [3]
CustomIterator
[2]
Definition
src_corelib_io_qabstractfileengine.cpp:58
CustomIterator::advance
bool advance() override
This pure virtual function advances the iterator to the next directory entry; if the operation was su...
Definition
src_corelib_io_qabstractfileengine.cpp:68
CustomIterator::currentFileName
QString currentFileName() override
Definition
src_corelib_io_qabstractfileengine.cpp:79
CustomIterator::CustomIterator
CustomIterator(const QString &path, const QStringList &nameFilters, QDir::Filters filters)
Definition
src_corelib_io_qabstractfileengine.cpp:60
ZipEngineHandler
Definition
src_corelib_io_qabstractfileengine.cpp:8
ZipEngineHandler::create
std::unique_ptr< QAbstractFileEngine > create(const QString &fileName) const override
[0]
Definition
src_corelib_io_qabstractfileengine.cpp:13
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
qtbase
src
corelib
doc
snippets
code
src_corelib_io_qabstractfileengine.cpp
Generated on
for Qt by
1.18.0