Results 1 to 3 of 3

Thread: Changing QString to upper case

  1. #1
    Join Date
    Apr 2017
    Posts
    55
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Changing QString to upper case

    I am taking a number from a QSpinBox and converting it to Hex using the following line of code

    Qt Code:
    1. QString number = QString("%1").arg(ui->spinBox_sens_nbr->value(), 2, 16, QChar('0'));
    To copy to clipboard, switch view to plain text mode 

    I works, giving 0a, or 0b etc. But now I need the hex number in upper case, 0A, 0B etc.....

    Simply adding .toUpper(); is not working.

    Anyone got a simple fix for this??

    Thanks much

    I got it to work using

    QString number = (QString("%1").arg(ui->spinBox_sens_nbr->value(), 2, 16, QChar('0')).toUpper());

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Changing QString to upper case

    for example
    Qt Code:
    1. QString out = QStringLiteral("0x%1").arg(QString::asprintf("%X", ui->spinBox_sens_nbr->value()), 16, QLatin1Char('0'));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2020
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Changing QString to upper case

    Quote Originally Posted by ChristianEhrlicher View Post
    for example
    Qt Code:
    1. QString out = QStringLiteral("0x%1").arg(QString::asprintf("%X", ui->spinBox_sens_nbr->value()), 16, QLatin1Char('0'));
    To copy to clipboard, switch view to plain text mode 
    We do not recommend using QString::asprintf() in new Qt code.

    My Qt6 version
    Qt Code:
    1. const QString out("0x"+QString("%1").arg(ui->spinBox_sens_nbr->value(), 2, 16, QChar('0')).toUpper());
    To copy to clipboard, switch view to plain text mode 

    output example:
    0xFC

Similar Threads

  1. convert upper-case to lower-case
    By RENOLD in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2012, 07:30
  2. QKeyEvent - lower case vs upper case keys?
    By ArkKup in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2012, 15:58
  3. QDataStream << QMultiHash upper bounds?
    By ucntcme in forum Qt Programming
    Replies: 2
    Last Post: 25th June 2009, 22:40
  4. upper case input
    By Lele in forum Qt Programming
    Replies: 1
    Last Post: 2nd October 2006, 09:44
  5. Upper case in QDateTime !!!!
    By paranoid_android in forum Qt Programming
    Replies: 4
    Last Post: 15th March 2006, 08:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.