Hi
I've used QString many many times before but the following does not make any sense to me. I have this code:
int minor = 0;
int major = 0;
if (minor <= 9)
version
= QString("%1%200%3").
arg(major
).
arg(seperator
).
arg(minor
);
else if (minor <= 99)
version
= QString("%1%20%3").
arg(major
).
arg(seperator
).
arg(minor
);
else
version
= QString("%1%2%3").
arg(major
).
arg(seperator
).
arg(minor
);
qDebug() << seperator;
qDebug() << version;
QString version;
QString seperator = QString(".");
int minor = 0;
int major = 0;
if (minor <= 9)
version = QString("%1%200%3").arg(major).arg(seperator).arg(minor);
else if (minor <= 99)
version = QString("%1%20%3").arg(major).arg(seperator).arg(minor);
else
version = QString("%1%2%3").arg(major).arg(seperator).arg(minor);
qDebug() << seperator;
qDebug() << version;
To copy to clipboard, switch view to plain text mode
Amazingly the qDebug() outputs gives:
"."
"000."
"."
"000."
To copy to clipboard, switch view to plain text mode
While the result should clearly be "0.000"
If anyone can give an explanation why version is wrong, I would really appreciate it.
Thanks,
Jac
Added after 12 minutes:
Solved it:
QString version = QString::number(major) + QString(".%1").arg(minor,3,10,QChar('0'));
To copy to clipboard, switch view to plain text mode
Bookmarks