PDA

View Full Version : Newline char combination in qstring



MarkoSan
12th May 2008, 10:46
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?

wysota
12th May 2008, 10:56
\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?

MarkoSan
12th May 2008, 11:33
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:
1 Coca Cola
2.5 2 5. I am now facing problems regarding currency formats and merchandize id formats ... The output should like this:
000001 Coca Cola
2,50 002 5,00 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?

wysota
12th May 2008, 11:38
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.

MarkoSan
12th May 2008, 12:04
Well, here is my test code:
tmpOrder.iMerchandizeID=1;
tmpOrder.iMerchandizeQuantity=25;
tmpOrder.rMerchandizePrice=4.00;
tmpOrder.rSubtotal=tmpOrder.iMerchandizeQuantity*t mpOrder.rMerchandizePrice;
tmpOrder.strMerchandizeName=QString("Testni Artikel");
tmpOrder.strDisplayString=QString::number(tmpOrder .iMerchandizeID)+strMerchandizeSpaceDelimiter+\
QString(tmpOrder.strMerchandizeName)+strMerchandiz eDelimiter+\
QString::number(tmpOrder.rMerchandizePrice, 'f', iMerchandizePricePrecision)+strMerchandizeSpaceDel imiter+\
QString::number(tmpOrder.iMerchandizeQuantity)+str MerchandizeSpaceDelimiter+\
QString::number(tmpOrder.rSubtotal, 'f', iMerchandizePricePrecision);Now the float values (price per unit and subtotal) are ok, but as you can see I do not use .arg function.

wysota
12th May 2008, 12:18
But you use QString::number() which is exactly the same.