Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QString & QString::sprintf ( const char *  cformat,

Safely builds a formatted string from the format string cformat and an arbitrary list of arguments.

The lc escape sequence expects a unicode character of type ushort (as returned by QChar::unicode()). The ls escape sequence expects a pointer to a zero-terminated array of unicode characters of type ushort (as returned by QString::utf16()).

The format string supports most of the conversion specifiers provided by printf() in the standard C++ library. It doesn't honor the length modifiers (e.g. h for short, ll for {long long}). If you need those, use the standard snprintf() function instead:

snippets/qstring/main.cpp Widget::splitFunction() size_t QString str

We do not recommend using QString::sprintf() in new Qt code. Instead, consider using QTextStream or arg(), both of which support Unicode strings seamlessly and are type-safe. Here's an example that uses QTextStream:
snippets/qstring/main.cpp Widget::splitFunction() QString result // result == "pi = 3.14"

For {QObject::tr()}{translations}, especially if the strings contains more than one escape sequence, you should consider using the arg() function instead. This allows the order of the replacements to be controlled by the translator.

See also:

Definition at line 4588 of file qstring.cpp.

References vsprintf().

Referenced by QWindowsStyle::drawPrimitive(), QGLWidget::fontDisplayListBase(), Q3MainWindow::isDockEnabled(), QColor::name(), QTextStream::operator<<(), Q3TextStream::operator<<(), Q3MainWindow::setDockEnabled(), Q3ProgressBar::setIndicator(), QHostAddress::toString(), and Q3UriDrag::unicodeUriToUri().

    va_list ap;
    va_start(ap, cformat);
    QString &s = vsprintf(cformat, ap);
    return s;

Generated by  Doxygen 1.6.0   Back to index