Skip to main content

QString

Struct QString 

Source
pub struct QString { /* private fields */ }
Expand description

The QString class provides a Unicode character string.

Note that QString is encoded in UTF-16, whereas Rust’s String is encoded in UTF-8.

Qt Documentation: QString

Implementations§

Source§

impl QString

Source

pub fn append<'a>(&'a mut self, str: &QString) -> &'a mut QString

Appends the string str onto the end of this string.

Source

pub fn clear(&mut self)

Clears the contents of the string and makes it null.

Source

pub fn contains(&self, str: &QString, cs: CaseSensitivity) -> bool

Returns true if this string contains an occurrence of the string str; otherwise returns false.

If cs is CaseSensitivity::CaseSensitive, the search is case-sensitive; otherwise the search is case-insensitive.

Source

pub fn ends_with(&self, s: &QString, cs: CaseSensitivity) -> bool

Returns true if the string ends with s; otherwise returns false.

If cs is CaseSensitivity::CaseSensitive, the search is case-sensitive; otherwise the search is case-insensitive.

Source

pub fn is_empty(&self) -> bool

Returns true if the string has no characters; otherwise returns false.

Source

pub fn is_lower(&self) -> bool

Returns true if the string is lowercase, that is, it’s identical to its to_lower folding.

Source

pub fn is_null(&self) -> bool

Returns true if this string is null; otherwise returns false.

Source

pub fn is_right_to_left(&self) -> bool

Returns true if the string is read right to left.

Source

pub fn is_upper(&self) -> bool

Returns true if the string is uppercase, that is, it’s identical to its to_upper folding.

Source

pub fn is_valid_utf16(&self) -> bool

Returns true if the string contains valid UTF-16 encoded data, or false otherwise.

Source

pub fn prepend<'a>(&'a mut self, str: &QString) -> &'a mut QString

Prepends the string str to the beginning of this string and returns a mutable reference to this string.

Source

pub fn remove<'a>( &'a mut self, str: &QString, cs: CaseSensitivity, ) -> &'a mut QString

Removes every occurrence of the given str string in this string, and returns a mutable reference to this string.

If cs is CaseSensitivity::CaseSensitive, the search is case-sensitive; otherwise the search is case-insensitive.

Source

pub fn replace<'a>( &'a mut self, before: &QString, after: &QString, cs: CaseSensitivity, ) -> &'a mut QString

Replaces every occurrence of the string before with the string after and returns a mutable reference to this string.

If cs is CaseSensitivity::CaseSensitive, the search is case-sensitive; otherwise the search is case-insensitive.

Source

pub fn starts_with(&self, s: &QString, cs: CaseSensitivity) -> bool

Returns true if the string starts with s; otherwise returns false.

Source

pub fn to_html_escaped(&self) -> QString

Converts a plain text string to an HTML string with HTML metacharacters <, >, &, and " replaced by HTML entities.

Source§

impl QString

Source

pub fn arg(&self, a: &QString) -> Self

Returns a copy of this string with the lowest numbered place marker replaced by string a, i.e., %1, %2, …, %99.

If there is no unreplaced place-marker remaining, a warning message is printed and the result is undefined. Place-marker numbers must be in the range 1 to 99.

Source

pub fn as_slice(&self) -> &[u16]

Extracts a slice containing the entire UTF-16 array.

Source

pub fn compare(&self, other: &QString, cs: CaseSensitivity) -> Ordering

Lexically compares this string with the other string.

If cs is CaseSensitivity::CaseSensitive, the comparison is case-sensitive; otherwise the comparison is case-insensitive.

Case sensitive comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect.

Source

pub fn index_of(&self, str: &QString, from: isize, cs: CaseSensitivity) -> isize

Returns the index position of the first occurrence of the string str in this string, searching forward from index position from. Returns -1 if str is not found.

If cs is CaseSensitivity::CaseSensitive, the search is case-sensitive; otherwise the comparison is case-insensitive.

Source

pub fn insert<'a>(&'a mut self, position: isize, str: &Self) -> &'a mut Self

Inserts the string str at the given index position and returns a mutable reference to this string.

Source

pub fn left(&self, n: isize) -> Self

Returns a substring that contains the n leftmost characters of the string.

Source

pub fn len(self: &QString) -> isize

Returns the number of characters in this string.

Source

pub fn mid(&self, position: isize, n: isize) -> Self

Returns a string that contains n characters of this string, starting at the specified position index.

Source

pub fn right(&self, n: isize) -> Self

Returns a substring that contains the n rightmost characters of the string.

Source

pub fn simplified(&self) -> Self

Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.

Whitespace characters are the ASCII characters tabulation '\t', line feed '\n', carriage return '\r', vertical tabulation '\x08' ('\v' in C), form feed '\x0C' ('\f' in C), and space ' '.

Source

pub fn split( &self, sep: &QString, behavior: SplitBehaviorFlags, cs: CaseSensitivity, ) -> QStringList

Splits the string into substrings wherever sep occurs, and returns the list of those strings. If sep does not match anywhere in the string, this function returns a single-element list containing this string.

cs specifies whether sep should be matched case sensitively or case insensitively.

If behavior is SplitBehaviorFlags::SkipEmptyParts, empty entries don’t appear in the result.

Source

pub fn to_latin1(&self) -> QByteArray

Returns a Latin-1 representation of the string as a QByteArray.

The returned byte array is undefined if the string contains non-Latin1 characters. Those characters may be suppressed or replaced with a question mark.

Source

pub fn to_local8bit(&self) -> QByteArray

Returns the local 8-bit representation of the string as a QByteArray.

If this string contains any characters that cannot be encoded in the local 8-bit encoding, the returned byte array is undefined. Those characters may be suppressed or replaced by another.

Source

pub fn to_lower(&self) -> Self

Returns a lowercase copy of the string.

Source

pub fn to_upper(&self) -> Self

Returns an uppercase copy of the string.

Source

pub fn to_utf8(&self) -> QByteArray

Returns a UTF-8 representation of the string as a QByteArray.

Source

pub fn trimmed(&self) -> Self

Returns a string that has whitespace removed from the start and the end.

Whitespace characters are the ASCII characters tabulation '\t', line feed '\n', carriage return '\r', vertical tabulation '\x08' ('\v' in C), form feed '\x0C' ('\f' in C), and space ' '.

Trait Implementations§

Source§

impl Add for QString

Source§

type Output = QString

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl Clone for QString

Source§

fn clone(&self) -> Self

Constructs a copy of this string.

This operation takes constant time, because QString is implicitly shared. This makes returning a QString from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QString

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QString

Source§

fn default() -> Self

Constructs a null string. Null strings are also empty.

Source§

impl<'de> Deserialize<'de> for QString

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for QString

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format the QString as a Rust string.

Note that this converts from UTF-16 to UTF-8.

Source§

impl Drop for QString

Source§

fn drop(&mut self)

Destroys the string.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Eq for QString

Source§

impl ExternType for QString

Source§

type Id = (Q, S, t, r, i, n, g)

A type-level representation of the type’s C++ namespace and type name. Read more
Source§

type Kind = Trivial

Source§

impl<'a> From<&'a QString> for QAnyStringView<'a>

Available on cxxqt_qt_version_major=6 only.
Source§

fn from(string: &'a QString) -> Self

Constructs a QAnyStringView from a QString.

Source§

impl From<&QString> for String

Source§

fn from(qstring: &QString) -> Self

Constructs a Rust String from a QString reference.

Note that this converts from UTF-16 to UTF-8.

Source§

impl From<&QString> for QStringList

Source§

fn from(string: &QString) -> Self

Constructs a string list that contains the given string.

Source§

impl From<&QString> for QUrl

Source§

fn from(str: &QString) -> Self

Constructs a QUrl from a QString.

Source§

impl From<&QString> for QUuid

Source§

fn from(value: &QString) -> Self

Creates a QUuid object from the string text, which must be formatted as five hex fields separated by ‘-’, e.g., “{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}” where each ‘x’ is a hex digit. The curly braces shown here are optional, but it is normal to include them.

If the conversion fails, a null UUID is returned.

Source§

impl From<&String> for QString

Source§

fn from(str: &String) -> Self

Constructs a QString from a Rust String reference.

Note that this converts from UTF-8 to UTF-16.

Source§

impl From<&str> for QString

Source§

fn from(str: &str) -> Self

Constructs a QString from a string slice.

Note that this converts from UTF-8 to UTF-16.

Source§

impl From<QString> for String

Source§

fn from(qstring: QString) -> Self

Constructs a Rust String from a QString.

Note that this converts from UTF-16 to UTF-8.

Source§

impl From<QUuid> for QString

Source§

fn from(value: QUuid) -> Self

Converts to this type from the input type.
Source§

impl From<String> for QString

Source§

fn from(str: String) -> Self

Constructs a QString from a Rust String.

Note that this converts from UTF-8 to UTF-16.

Source§

impl<'a> FromIterator<&'a QString> for QStringList

Source§

fn from_iter<I: IntoIterator<Item = &'a QString>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<QString> for QStringList

Source§

fn from_iter<I: IntoIterator<Item = QString>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Ord for QString

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for QString

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for QString

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl QListElement for QString

Source§

type TypeId = (Q, L, i, s, t, __, Q, S, t, r, i, n, g)

Source§

fn append(list: &mut QList<Self>, value: Self)

Source§

fn append_clone(list: &mut QList<Self>, value: &Self)

Source§

fn clear(list: &mut QList<Self>)

Source§

fn clone(list: &QList<Self>) -> QList<Self>

Source§

fn contains(list: &QList<Self>, value: &Self) -> bool

Source§

fn default() -> QList<Self>

Source§

fn drop(list: &mut QList<Self>)

Source§

unsafe fn get_unchecked(list: &QList<Self>, pos: isize) -> &Self

Safety Read more
Source§

fn index_of(list: &QList<Self>, value: &Self) -> isize

Source§

fn insert(list: &mut QList<Self>, pos: isize, value: Self)

Source§

fn insert_clone(list: &mut QList<Self>, pos: isize, value: &Self)

Source§

fn len(list: &QList<Self>) -> isize

Source§

fn remove(list: &mut QList<Self>, pos: isize)

Source§

fn reserve(list: &mut QList<Self>, size: isize)

Source§

impl QSetElement for QString

Source§

type TypeId = (Q, S, e, t, __, Q, S, t, r, i, n, g)

Source§

fn clear(set: &mut QSet<Self>)

Source§

fn clone(set: &QSet<Self>) -> QSet<Self>

Source§

fn contains(set: &QSet<Self>, value: &Self) -> bool

Source§

fn default() -> QSet<Self>

Source§

fn drop(set: &mut QSet<Self>)

Source§

unsafe fn get_unchecked(set: &QSet<Self>, pos: isize) -> &Self

Safety Read more
Source§

fn insert(set: &mut QSet<Self>, value: Self)

Source§

fn insert_clone(set: &mut QSet<Self>, value: &Self)

Source§

fn len(set: &QSet<Self>) -> isize

Source§

fn remove(set: &mut QSet<Self>, value: &Self) -> bool

Source§

fn reserve(set: &mut QSet<Self>, size: isize)

Source§

impl QVariantValue for QString

Source§

fn can_convert(variant: &QVariant) -> bool

Source§

fn construct(value: &Self) -> QVariant

Source§

fn value_or_default(variant: &QVariant) -> Self

Source§

impl QVectorElement for QString

Source§

type TypeId = (Q, V, e, c, t, o, r, __, Q, S, t, r, i, n, g)

Source§

fn append(vector: &mut QVector<Self>, value: Self)

Source§

fn append_clone(vector: &mut QVector<Self>, value: &Self)

Source§

fn clear(vector: &mut QVector<Self>)

Source§

fn clone(vector: &QVector<Self>) -> QVector<Self>

Source§

fn contains(vector: &QVector<Self>, value: &Self) -> bool

Source§

fn default() -> QVector<Self>

Source§

fn drop(vector: &mut QVector<Self>)

Source§

unsafe fn get_unchecked(vector: &QVector<Self>, pos: isize) -> &Self

Safety Read more
Source§

fn index_of(vector: &QVector<Self>, value: &Self) -> isize

Source§

fn insert(vector: &mut QVector<Self>, pos: isize, value: Self)

Source§

fn insert_clone(vector: &mut QVector<Self>, pos: isize, value: &Self)

Source§

fn len(vector: &QVector<Self>) -> isize

Source§

fn remove(vector: &mut QVector<Self>, pos: isize)

Source§

fn reserve(vector: &mut QVector<Self>, size: isize)

Source§

impl Serialize for QString

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&QString> for QColor

Available on crate feature qt_gui only.
Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from(value: &QString) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.