QString str = "Hello World"; QString substr = str.left(5); // substr will be "Hello"
QString str = "12345"; QString substr = str.left(10); // substr will be "12345"In this example, `left(10)` retrieves the entire string since it is shorter than 10 characters. This function is part of the Qt library, specifically the QtCore package.