Il 18/09/19 13:16, Jason H ha scritto:
What's the best way to zero-pad a QByteArray?
What I want is QByteArray("%1").arg(6, 10, 10, '0')

Mostly it has to do with the fact that QByteArray is sitting between two worlds; on one side it's just a container of bytes, on the other side it has _some_ manipulation functions for ASCII-like strings. "Some" because, as you've noticed, stuff like the arg() convenience is missing.

If you really need a QByteArray you can work around this by e.g. using a printf-like function, what you're looking for is the "%010d" formatting.

Pseudocode:

int n = 123;
const char *format = "The number is %010d";
auto size = qsnprintf(nullptr, 0, format, n);

QByteArray result(size, Qt::uninitialized);
qsnprintf(result.data(), result.size(), format, n);


HTH,
--
Giuseppe D'Angelo | [email protected] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Interest mailing list
[email protected]
https://lists.qt-project.org/listinfo/interest

Reply via email to