slint::SharedString Struct
struct SharedString;#include <slint.h>A string type used by the Slint run-time.
SharedString uses implicit data sharing to make it efficient to pass around copies. When copying, a reference to the data is cloned, not the data itself.
The class provides constructors from std::string_view ↗ as well as the automatic conversion to a std::string_view ↗.
For convenience, it’s also possible to convert a number to a string using SharedString::from_number(double).
Under the hood the string data is UTF-8 encoded and it is always terminated with a null character.
Public Functions
Section titled “Public Functions” SharedString
Section titled “ SharedString”slint::SharedString::SharedString()
Creates an empty default constructed string.
SharedString
Section titled “ SharedString”slint::SharedString::SharedString(std::string_view s)
Creates a new SharedString from the string view s. The underlying string data is copied.
SharedString
Section titled “ SharedString”slint::SharedString::SharedString(const char *s)
Creates a new SharedString from the null-terminated string pointer s. The underlying string data is copied. It is assumed that the string is UTF-8 encoded.
SharedString
Section titled “ SharedString”slint::SharedString::SharedString(const char8_t *s)
Creates a new SharedString from the null-terminated string pointer s. The underlying string data is copied.
SharedString
Section titled “ SharedString”slint::SharedString::SharedString(std::u8string_view s)
Creates a new SharedString from the string view s. The underlying string data is copied.
SharedString
Section titled “ SharedString”slint::SharedString::SharedString(const SharedString &other)
Creates a new SharedString from other.
~SharedString
Section titled “ ~SharedString”slint::SharedString::~SharedString()
Destroys this SharedString and frees the memory if this is the last instance referencing it.
operator=
Section titled “ operator=”SharedString & slint::SharedString::operator=(const SharedString &other)
Assigns other to this string and returns a reference to this string.
operator=
Section titled “ operator=”SharedString & slint::SharedString::operator=(std::string_view s)
Assigns the string view s to this string and returns a reference to this string. The underlying string data is copied. It is assumed that the string is UTF-8 encoded.
operator=
Section titled “ operator=”SharedString & slint::SharedString::operator=(const char *s)
Assigns null-terminated string pointer s to this string and returns a reference to this string. The underlying string data is copied. It is assumed that the string is UTF-8 encoded.
operator=
Section titled “ operator=”SharedString & slint::SharedString::operator=(SharedString &&other)
Move-assigns other to this SharedString instance.
operator std::string_view
Section titled “ operator std::string_view”slint::SharedString::operator std::string_view() const
Provides a view to the string data. The returned view is only valid as long as at least this SharedString exists.
auto slint::SharedString::data() const -> const char *
Provides a raw pointer to the string data. The returned pointer is only valid as long as at least this SharedString exists.
std::size_t slint::SharedString::size() const
Size of the string, in bytes. This excludes the terminating null character.
const char * slint::SharedString::begin() const
Returns a pointer to the first character. It is only safe to dereference the pointer if the string contains at least one character.
const char * slint::SharedString::end() const
Returns a point past the last character of the string. It is not safe to dereference the pointer, but it is suitable for comparison.
bool slint::SharedString::empty() const
Returns: true if the string contains no characters; false otherwise.
starts_with
Section titled “ starts_with”bool slint::SharedString::starts_with(std::string_view prefix) const
Returns: true if the string starts with the specified prefix string; false otherwise
ends_with
Section titled “ ends_with”bool slint::SharedString::ends_with(std::string_view prefix) const
Returns: true if the string ends with the specified prefix string; false otherwise
void slint::SharedString::clear()
Reset to an empty string.
to_lowercase
Section titled “ to_lowercase”SharedString slint::SharedString::to_lowercase() const
Returns the lowercase equivalent of this string, as a new SharedString.
For example:
auto str = slint::SharedString("Hello");auto str2 = str.to_lowercase(); // creates "hello" to_uppercase
Section titled “ to_uppercase”SharedString slint::SharedString::to_uppercase() const
Returns the uppercase equivalent of this string, as a new SharedString.
For example:
auto str = slint::SharedString("Hello");auto str2 = str.to_uppercase(); // creates "HELLO" operator+=
Section titled “ operator+=”SharedString & slint::SharedString::operator+=(std::string_view other)
Appends other to this string and returns a reference to this.
Public Static Functions
Section titled “Public Static Functions” from_number
Section titled “ from_number”static SharedString slint::SharedString::from_number(double n)
Creates a new SharedString from the given number n. The string representation of the number uses a minimal formatting scheme: If n has no fractional part, the number will be formatted as an integer.
For example:
auto str = slint::SharedString::from_number(42); // creates "42"auto str2 = slint::SharedString::from_number(100.5) // creates "100.5"Friends
Section titled “Friends” operator==
Section titled “ operator==”bool operator==(const SharedString &a, const SharedString &b)
Returns true if a is equal to b; otherwise returns false.
operator!=
Section titled “ operator!=”bool operator!=(const SharedString &a, const SharedString &b)
Returns true if a is not equal to b; otherwise returns false.
operator<
Section titled “ operator<”bool operator<(const SharedString &a, const SharedString &b)
Returns true if a is lexicographically less than b; false otherwise.
operator<=
Section titled “ operator<=”bool operator<=(const SharedString &a, const SharedString &b)
Returns true if a is lexicographically less or equal than b; false otherwise.
operator>
Section titled “ operator>”bool operator>(const SharedString &a, const SharedString &b)
Returns true if a is lexicographically greater than b; false otherwise.
operator>=
Section titled “ operator>=”bool operator>=(const SharedString &a, const SharedString &b)
Returns true if a is lexicographically greater or equal than b; false otherwise.
operator<<
Section titled “ operator<<”std::ostream & operator<<(std::ostream &stream, const SharedString &shared_string)
Writes the shared_string to the specified stream and returns a reference to the stream.
operator+
Section titled “ operator+”SharedString operator+(const SharedString &a, std::string_view b)
Concatenates a and and returns the result as a new SharedString.
operator+
Section titled “ operator+”SharedString operator+(SharedString &&a, std::string_view b)
Move-concatenates b to and returns a reference to a.
© 2026 SixtyFPS GmbH