Pages
API Documentation
On this page

KIO::UDSEntry Class

Universal Directory Service. More...

  • Header: #include <KIO/UDSEntry>
  • CMake: find_package(KF6 REQUIRED COMPONENTS KIO)
    target_link_libraries(mytarget PRIVATE KF6::KIOCore)

List of all members, including inherited members
Deprecated members

Public Types

Public Functions

Detailed Description

UDS entry is the data structure representing all the fields about a given URL (file or directory).

The KIO::listDir() and KIO:stat() operations use this data structure.

KIO defines a number of standard fields, see UDSEntry::StandardFieldTypes enum.

For instance, to retrieve the display name of the entry, use:

QString displayName = entry.stringValue( KIO::UDSEntry::UDS_DISPLAY_NAME );

To know the modification time of the file/url in seconds since UNIX epoch, use:

QDateTime mtime = QDateTime::fromSecsSinceEpoch(entry.numberValue(KIO::UDSEntry::UDS_MODIFICATION_TIME, 0));
if (mtime.isValid())
    ...

If you need higher precision for the modification time, you can also check if UDS_MODIFICATION_TIME_NS_OFFSET is supported:

if (entry.contains(KIO::UDSEntry::UDS_MODIFICATION_TIME_NS_OFFSET)) {
    long long totalMSecs = (entry.numberValue(KIO::UDSEntry::UDS_MODIFICATION_TIME, 0) * 1000LL)
                          + entry.numberValue(KIO::UDSEntry::UDS_MODIFICATION_TIME_NS_OFFSET, 0) / 1000000LL);

    QDateTime mtime = QDateTime::fromMSecsSinceEpoch(totalMSecs);

Member Type Documentation

enum UDSEntry::ItemTypes

Bit field used to specify the item type of a StandardFieldTypes.

Constant Value Description
KIO::UDSEntry::UDS_STRING 0x01000000 Indicates that the field is a QString
KIO::UDSEntry::UDS_NUMBER 0x02000000 Indicates that the field is a number (long long)
KIO::UDSEntry::UDS_TIME `0x04000000 UDS_NUMBER`

enum UDSEntry::StandardFieldTypes

Constants used to specify the type of a UDSEntry’s field.

Constant Value Description
KIO::UDSEntry::UDS_SIZE `1 UDS_NUMBER`
KIO::UDSEntry::UDS_USER `3 UDS_STRING`
KIO::UDSEntry::UDS_ICON_NAME `4 UDS_STRING`
KIO::UDSEntry::UDS_GROUP `5 UDS_STRING`
KIO::UDSEntry::UDS_NAME `6 UDS_STRING`
KIO::UDSEntry::UDS_LOCAL_PATH `7 UDS_STRING`
KIO::UDSEntry::UDS_HIDDEN `8 UDS_NUMBER`
KIO::UDSEntry::UDS_ACCESS `9 UDS_NUMBER`
KIO::UDSEntry::UDS_MODIFICATION_TIME `10 UDS_TIME`
KIO::UDSEntry::UDS_ACCESS_TIME `11 UDS_TIME`
KIO::UDSEntry::UDS_CREATION_TIME `12 UDS_TIME`
KIO::UDSEntry::UDS_FILE_TYPE `13 UDS_NUMBER`
KIO::UDSEntry::UDS_LINK_DEST `14 UDS_STRING`
KIO::UDSEntry::UDS_URL `15 UDS_STRING`
KIO::UDSEntry::UDS_MIME_TYPE `16 UDS_STRING`
KIO::UDSEntry::UDS_GUESSED_MIME_TYPE `17 UDS_STRING`
KIO::UDSEntry::UDS_XML_PROPERTIES `18 UDS_STRING`
KIO::UDSEntry::UDS_EXTENDED_ACL `19 UDS_NUMBER`
KIO::UDSEntry::UDS_ACL_STRING `20 UDS_STRING`
KIO::UDSEntry::UDS_DEFAULT_ACL_STRING `21 UDS_STRING`
KIO::UDSEntry::UDS_DISPLAY_NAME (since Qt 4.1) `22 UDS_STRING`
KIO::UDSEntry::UDS_TARGET_URL (since Qt 4.1) `23 UDS_STRING`
KIO::UDSEntry::UDS_DISPLAY_TYPE (since Qt 4.4) `24 UDS_STRING`
KIO::UDSEntry::UDS_ICON_OVERLAY_NAMES (since Qt 4.5) `25 UDS_STRING`
KIO::UDSEntry::UDS_COMMENT (since Qt 4.6) `26 UDS_STRING`
KIO::UDSEntry::UDS_DEVICE_ID (since Qt 4.7.3) `27 UDS_NUMBER`
KIO::UDSEntry::UDS_INODE (since Qt 4.7.3) `28 UDS_NUMBER`
KIO::UDSEntry::UDS_RECURSIVE_SIZE (since Qt 5.70) `29 UDS_NUMBER`
KIO::UDSEntry::UDS_LOCAL_USER_ID (since Qt 6.0) `30 UDS_NUMBER`
KIO::UDSEntry::UDS_LOCAL_GROUP_ID (since Qt 6.0) `31 UDS_NUMBER`
KIO::UDSEntry::UDS_SUBVOL_ID (since Qt 6.23) `32 UDS_NUMBER`
KIO::UDSEntry::UDS_MOUNT_ID (since Qt 6.23) `33 UDS_NUMBER`
KIO::UDSEntry::UDS_MODIFICATION_TIME_NS_OFFSET (since Qt 6.24) `34 UDS_NUMBER`
KIO::UDSEntry::UDS_ACCESS_TIME_NS_OFFSET (since Qt 6.24) `35 UDS_NUMBER`
KIO::UDSEntry::UDS_CREATION_TIME_NS_OFFSET (since Qt 6.24) `36 UDS_NUMBER`
KIO::UDSEntry::UDS_SIZE_ON_DISK (since Qt 6.30) `37 UDS_NUMBER`
KIO::UDSEntry::UDS_EXTRA `100 UDS_STRING`
KIO::UDSEntry::UDS_EXTRA_END `140 UDS_STRING`

Member Function Documentation

UDSEntry::UDSEntry()

UDSEntry::UDSEntry(const struct stat64 &buff, const QString &name = QString())

Create a UDSEntry by QT_STATBUF

buff QT_STATBUF object

name filename

UDSEntry::UDSEntry(const KIO::UDSEntry &)

Copy constructor

void UDSEntry::clear()

remove all fields

bool UDSEntry::contains(uint field) const

check existence of a field

field numeric field id

int UDSEntry::count() const

The number of fields

void UDSEntry::fastInsert(uint field, const QString &value)

Insert field with string value, it will assert if the field is already inserted. In that case, use replace() instead. field numeric field id value to set

void UDSEntry::fastInsert(uint field, long long l)

Insert field with numeric value, it will assert if the field is already inserted. In that case, use replace() instead. field numeric field id l value to set

QList<uint> UDSEntry::fields() const

A vector of fields being present for the current entry.

Returns all fields for the current entry.

[since 6.29] void UDSEntry::insert(std::initializer_list<std::pair<uint, const QString &>> fieldValuePairs)

Insert the values passed as pairs {field, value} in a initializer_list

This will first pre-allocate the necessary memory in the underlying storage vector.

Example:

UDSEntry entry;
entry.insert({{UDS_SIZE, 0}, {UDS_ACCESS, 0}});

fieldValuePairs the fields and the values to insert

This function was introduced in Qt 6.29.

[since 6.29] void UDSEntry::insert(std::initializer_list<std::pair<uint, long long>> fieldValuePairs)

Insert the values passed as pairs {field, value} in a initializer_list

This will first pre-allocate the necessary memory in the underlying storage vector.

Example:

UDSEntry entry;
entry.insert({{UDS_NAME, ""}, {UDS_USER, ""}});

fieldValuePairs the fields and the values to insert

This function was introduced in Qt 6.29.

bool UDSEntry::isDir() const

Returns true if this entry is a directory (or a link to a directory)

Returns true if this entry is a link

long long UDSEntry::numberValue(uint field, long long defaultValue = 0) const

Returns value of a numeric field

[since 6.29] int UDSEntry::numbersCount() const

The number of number fields (including time fields)

This function was introduced in Qt 6.29.

void UDSEntry::replace(uint field, const QString &value)

Replace or insert field with string value field numeric field id value to set

void UDSEntry::replace(uint field, long long l)

Replace or insert field with numeric value field numeric field id l value to set

[since 6.29] void UDSEntry::reserve(std::initializer_list<uint> fields)

Pre-allocate fields fields in the backend storage according to their UDS_TYPE

Example:

UDSEntry entry;
entry.reserve({UDS_SIZE, UDS_ACCESS, UDS_MODIFICATION_TIME, UDS_NAME});

fields the fields to pre-allocate for

This function was introduced in Qt 6.29.

[since 6.29] void UDSEntry::reserveNumbers(int size)

Calling this function before inserting items into an empty UDSEntry may save time and memory.

size number of UDS_NUMBER fields for which memory will be pre-allocated

This function was introduced in Qt 6.29.

See also reserveStrings()

[since 6.29] void UDSEntry::reserveStrings(int size)

Calling this function before inserting items into an empty UDSEntry may save time and memory.

size number of UDS_STRING fields for which memory will be pre-allocated

This function was introduced in Qt 6.29.

See also reserveNumbers()

QString UDSEntry::stringValue(uint field) const

Returns value of a textual field

[since 6.29] int UDSEntry::stringsCount() const

The number of string fields

This function was introduced in Qt 6.29.

UDSEntryList

A directory listing is a list of UDSEntry instances.

To list the name and size of all the files in a directory listing you would do:

KIO::UDSEntryList::ConstIterator it = entries.begin();
const KIO::UDSEntryList::ConstIterator end = entries.end();
for (; it != end; ++it) {
  const KIO::UDSEntry& entry = *it;
  QString name = entry.stringValue( KIO::UDSEntry::UDS_NAME );
  bool isDir = entry.isDir();
  KIO::filesize_t size = entry.numberValue( KIO::UDSEntry::UDS_SIZE, -1 );
  ...
}
We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.