Results 1 to 6 of 6

Thread: Newline char combination in qstring

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Newline char combination in qstring

    Hi to all!

    I've been trying to force newline into QString but old asm and c trick with "\n" simply does not work. Which char do I have to insert into unicode string to get newline?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Newline char combination in qstring

    \n is no trick and works fine with QString. You must have done something wrong. Can we see the code and the error message you get?

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Newline char combination in qstring

    Wysotta, i found a mistake, I was using const char* for "\n" instead of QString("\n"). Now it works fine. But now I have another question. I get following output:
    Qt Code:
    1. 1 Coca Cola
    2. 2.5 2 5
    To copy to clipboard, switch view to plain text mode 
    . I am now facing problems regarding currency formats and merchandize id formats ... The output should like this:
    Qt Code:
    1. 000001 Coca Cola
    2. 2,50 002 5,00
    To copy to clipboard, switch view to plain text mode 
    Now, in the first line, the number represents merchandize id (from mysql table), and the string represents merchandize name. In the second line, the first number represents the price of merchandize, the second number represents the quantity of merchandize and the third number represents subtotal (quanty*price/item). How do I reformat this string?
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Newline char combination in qstring

    QString::arg() and QString::number() take parameters such as field length and fill character. If you want a comma instead of a dot, QLocale::toString() might be handy.

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Newline char combination in qstring

    Well, here is my test code:
    Qt Code:
    1. tmpOrder.iMerchandizeID=1;
    2. tmpOrder.iMerchandizeQuantity=25;
    3. tmpOrder.rMerchandizePrice=4.00;
    4. tmpOrder.rSubtotal=tmpOrder.iMerchandizeQuantity*tmpOrder.rMerchandizePrice;
    5. tmpOrder.strMerchandizeName=QString("Testni Artikel");
    6. tmpOrder.strDisplayString=QString::number(tmpOrder.iMerchandizeID)+strMerchandizeSpaceDelimiter+\
    7. QString(tmpOrder.strMerchandizeName)+strMerchandizeDelimiter+\
    8. QString::number(tmpOrder.rMerchandizePrice, 'f', iMerchandizePricePrecision)+strMerchandizeSpaceDelimiter+\
    9. QString::number(tmpOrder.iMerchandizeQuantity)+strMerchandizeSpaceDelimiter+\
    10. QString::number(tmpOrder.rSubtotal, 'f', iMerchandizePricePrecision);
    To copy to clipboard, switch view to plain text mode 
    Now the float values (price per unit and subtotal) are ok, but as you can see I do not use .arg function.
    Qt 5.3 Opensource & Creator 3.1.2

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Newline char combination in qstring

    But you use QString::number() which is exactly the same.

Similar Threads

  1. Char array[6] to QString and display it
    By arunvv in forum Newbie
    Replies: 11
    Last Post: 12th March 2014, 20:48
  2. Char Array to QString
    By 3nc31 in forum Qt Programming
    Replies: 2
    Last Post: 25th November 2007, 22:18
  3. QString to unsigned char *
    By darksaga in forum Qt Programming
    Replies: 9
    Last Post: 23rd July 2007, 07:52
  4. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  5. unable to save QCStrings properly in a buffer
    By nass in forum Qt Programming
    Replies: 13
    Last Post: 15th November 2006, 20:49

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.