-1

I try to replace QString img=":/images/f0000.png";

If pVaule is 51 img should be ":/images/f0001.png"

If pVaule is 71 img should be ":/images/f0021.png"

But my result is pVaule is 51 img

":/images/f000\u0001.png"

pVaule is 71 img

":/images/f00\u0002\u0001.png"

How to fix it?

5407
  • 39
  • 9

1 Answers1

2

You have to use the ASCII value of numbers...

if(pValue>=50 && pValue<=89)
{
    QString img=":/images/f0000.png";
    if(pValue>=50 && pValue<=59)
    {
        img.data()[12]='0';
        img.data()[13]='0'+char(pValue-50);
    }
    else if(pValue>=60 && pValue<=89)
    {
        img.data()[12]='0'+char(pValue-50)/10;
        img.data()[13]='0'+char(pValue-50)%10;
    }
}

Also, a better solution to this would be:

img.replace(10, 4, QString(4 - QString::number(pValue - 50).length()), '0') + QString::number(pValue - 50));
Ruks
  • 3,886
  • 1
  • 10
  • 22