10

I'm trying to create a QString which is a hexadecimal number with its letter digits in Capitals instead of small caps, how can it be done?

QString( " %1" ).arg( 15, 1, 16 )

yields f and I'd like F

George Hilliard
  • 15,402
  • 9
  • 58
  • 96
Petruza
  • 11,744
  • 25
  • 84
  • 136

1 Answers1

14

By converting the string to upper case:

QString( " %1" ).arg( 15, 1, 16 ).toUpper();

This returns an uppercase string. The method used to be called upper() in qt3.

George Hilliard
  • 15,402
  • 9
  • 58
  • 96
dantje
  • 1,739
  • 1
  • 13
  • 25
  • 4
    I guess that should be `toUpper()`. – mtvec Jun 19 '10 at 10:11
  • 1
    Do you know of any way to convert just the output of arg()? e.g. `QString("Here is my hex byte: %1.").arg((ushort)aByte,2,16,QChar('0'))` – M_M Jul 19 '17 at 10:48
  • 1
    @M_M you have to put the arg into another QString like this: `QString{"Here is my hex byte: 0x%1."}.arg(QString{"%1"}.arg((ushort)aByte, 2, 16, QChar{'0'}).toUpper())` – Peter Rawytsch Mar 26 '19 at 10:52
  • @PeterRawytsch I guess that works. It's a bit much for one line though. I was wondering if there was a more concise way. If not, I guess you're better off doing it on 2 lines: `1: QString aByte = QString( " %1" ).arg( 15, 1, 16 ); 2:QString("Here is my hex byte: %1.").arg(aByte.toUpper());` – M_M Apr 06 '19 at 10:35