Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qresource_iterator.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qresource.h"
6
7#include <QtCore/qvariant.h>
8
10
12 const QStringList &filterNames)
13 : QAbstractFileEngineIterator(filters, filterNames), index(-1)
14{
15}
16
18{
19}
20
22{
23 if (!hasNext())
24 return QString();
25 ++index;
26 return currentFilePath();
27}
28
30{
31 if (index == -1) {
32 // Lazy initialization of the iterator
33 QResource resource(path());
34 if (!resource.isValid())
35 return false;
36
37 // Initialize and move to the next entry.
38 entries = resource.children();
39 index = 0;
40 }
41
42 return index < entries.size();
43}
44
46{
47 if (index <= 0 || index > entries.size())
48 return QString();
49 return entries.at(index - 1);
50}
51
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines.
QString path() const
Returns the path for this iterator.
virtual QString currentFilePath() const
Returns the path to the current directory entry.
bool hasNext() const override
This pure virtual function returns true if there is at least one more entry in the current directory ...
QString next() override
This pure virtual function advances the iterator to the next directory entry, and returns the file pa...
QString currentFileName() const override
This pure virtual function returns the name of the current directory entry, excluding the path.
QResourceFileEngineIterator(QDir::Filters filters, const QStringList &filterNames)
\inmodule QtCore
Definition qresource.h:20
QStringList children() const
Returns a list of all resources in this directory, if the resource represents a file the list will be...
bool isValid() const
Returns true if the resource really exists in the resource hierarchy, false otherwise.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Combined button and popup list for selecting options.
GLuint index
[2]
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]