qt - Is this usage of arg ok? -
msg.append(qstring("\"settime\": %1000,") .arg(eventlist[i].failurebegin)); // set time
i know if it`s ok have %1 right next 000. since there 1 argument there no confusion possible qstring if had 10 .arg() confuse %10 right? there escape sequence or have break down concatenations?
it not ok. can explore source code of qstring::arg or let me show you.
qstring qstring::arg(qlonglong a, int fieldwidth, int base, qchar fillchar) const { argescapedata d = findargescapes(*this); if (d.occurrences == 0) { qwarning() << ""qstring::arg: argument missing:"" << *this << ',' << a; return *this; } //.... not important. }
this how findargescapes
implemented. think source code of qt more readable stl implementations.
static argescapedata findargescapes(const qstring &s) { const qchar *uc_begin = s.unicode(); const qchar *uc_end = uc_begin + s.length(); argescapedata d; d.min_escape = int_max; d.occurrences = 0; d.escape_len = 0; d.locale_occurrences = 0; const qchar *c = uc_begin; while (c != uc_end) { while (c != uc_end && c->unicode() != '%') ++c; if (c == uc_end) break; const qchar *escape_start = c; if (++c == uc_end) break; bool locale_arg = false; if (c->unicode() == 'l') { locale_arg = true; if (++c == uc_end) break; } int escape = c->digitvalue(); if (escape == -1) continue; ++c; if (c != uc_end) { int next_escape = c->digitvalue(); if (next_escape != -1) { escape = (10 * escape) + next_escape; //************* ++c; } } if (escape > d.min_escape) continue; if (escape < d.min_escape) { d.min_escape = escape; d.occurrences = 0; d.escape_len = 0; d.locale_occurrences = 0; } ++d.occurrences; if (locale_arg) ++d.locale_occurrences; d.escape_len += c - escape_start; } return d; }
Comments
Post a Comment