Search code examples
qtfill

filled with zeros


How can I fill with zeros at left? My code is:

QString reelId = QString("Month %1").arg(QDate::currentDate().month());
qDebug() << reelId;

and out is: Month 2 and I want Month 02;


Solution

  • The term you're really looking for is "pad", as in padding a string with something. Look through the QString documentation for this, specifically the various QString::arg() functions, which describes how to achieve this in a variety of ways :)