QStringRef Class

The QStringRef class provides a thin wrapper around QString substrings. More...

Header: #include <QStringRef>
qmake: QT += core
Since: Qt 4.3

This class was introduced in Qt 4.3.

Note: All functions in this class are reentrant.

Public Types

Detailed Description

QStringRef provides a read-only subset of the QString API.

A string reference explicitly references a portion of a string() with a given size(), starting at a specific position(). Calling toString() returns a copy of the data as a real QString instance.

This class is designed to improve the performance of substring handling when manipulating substrings obtained from existing QString instances. QStringRef avoids the memory allocation and reference counting overhead of a standard QString by simply referencing a part of the original string. This can prove to be advantageous in low level code, such as that used in a parser, at the expense of potentially more complex code.

For most users, there are no semantic benefits to using QStringRef instead of QString since QStringRef requires attention to be paid to memory management issues, potentially making code more complex to write and maintain.

Warning: A QStringRef is only valid as long as the referenced string exists. If the original string is deleted, the string reference points to an invalid memory location.

We suggest that you only use this class in stable code where profiling has clearly identified that performance improvements can be made by replacing standard string operations with the optimized substring handling provided by this class.

See also Implicitly Shared Classes.

Member Type Documentation

typedef QStringRef::const_iterator

This typedef was introduced in Qt 5.4.

See also QStringRef::const_reverse_iterator.

typedef QStringRef::const_reverse_iterator

This typedef was introduced in Qt 5.7.

See also QStringRef::const_iterator.