Problem with arg at QString.
-
wrote on 3 Jul 2011, 13:43 last edited by
Here is an example from the book
C++ GUI Programming with Qt 4 by Jasmin Blanchette; Mark Summerfield.// WRONG
@statusBar()->showMessage(tr("Host " + hostName + " found"));@
The solution is to use QString::arg():@statusBar()->showMessage(tr("Host %1 found").arg(hostName));@
-
wrote on 3 Jul 2011, 13:47 last edited by
And what would you have done if there was a second argument?
-
wrote on 3 Jul 2011, 13:49 last edited by
@statusBar()->showMessage(tr("Host %1 found %2").arg(hostName).arg(parameter));
@Do you know the book i mentioned? It's free and it has a complete chapter devoted to translating Qt applications.
-
wrote on 3 Jul 2011, 14:13 last edited by
Now i understand! Hmm i gave a try:
@ QString written = QString(tr("In random order") + ":\n" + "Leon Vytanos <" + "<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"<span>%1%2%3%4%5</span></a>").arg("leon.check.me@gmail.com").arg(">\nAlex Solanos <").arg("<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"</a>").arg("alexsol.developer@gmail.com").arg(">");
@No erros but the textbrowzer is somehow like this now..
!http://img36.imageshack.us/img36/3006/screenshot3izm.png(Screenshot)!I will be sure to take a look at the book.. Is it real free? Cause i see that at Amazon it costs 25$
-
wrote on 3 Jul 2011, 14:17 last edited by
you can find a link to the free book here :
-
wrote on 3 Jul 2011, 14:18 last edited by
Downloaded! What about the problem?
-
wrote on 3 Jul 2011, 14:19 last edited by
Hint : get rid of those "+" symbols in your string!
that's why you get those results as I explained already -
wrote on 3 Jul 2011, 14:22 last edited by
Yes but if get rid of "+" then the whole thing will be translatable.. I want only the "In random order" part to be..
P.S The second edition of the book is better? And the second is the one that is not free?
-
wrote on 3 Jul 2011, 14:27 last edited by
[quote author="Leon" date="1309702921"]Yes but if get rid of "+" then the whole thing will be translatable.. I want only the "In random order" part to be..[/quote]
Try the same without those plusses and you will see youself.
Tr() cannot translate as you think when those plusses are there. Read the book and it will be all clear to you.[quote]P.S The second edition of the book is better? And the second is the one that is not free?[/quote]
It's almost the same. The first one is free as the webpage tells you.
-
wrote on 3 Jul 2011, 14:34 last edited by
Tr() will translate only the “In random order” part even if there are plusses.. I just checked it..
I just removed every "+" exactly the same problem. :/@QString written = QString(tr("In random order%1%2%3%4%5%6%7%8")).arg(":\n").arg("Leon Vytanos <").arg("<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"<span>%1%2%3%4%5</span></a>").arg("leon.check.me@gmail.com").arg(">\nAlex Solanos <").arg("<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"</a>").arg("alexsol.developer@gmail.com").arg(">");
@ -
wrote on 3 Jul 2011, 14:41 last edited by
can you please use my example instead and tell me what you see.?
one more try :
you use one looooong QString and AT THE END you put the arg() one after another. Don't put the arg() in between. -
wrote on 3 Jul 2011, 14:54 last edited by
Ok look the code.. I removed the <span>%1%2%3%4%5</span> because it was wrong.. So this should work..
@QString written = QString(tr("In random order%1%2%3%4%5%6%7")).arg(":\nLeon Vytanos <").arg("<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"</a>").arg("leon.check.me@gmail.com").arg(">\nAlex Solanos <").arg("<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"</a>").arg("alexsol.developer@gmail.com").arg(">");
@I putted the outpout at tomboy notes and it look like this.. "SCREENSHOT":http://img843.imageshack.us/img843/8437/screenshot4rp.png
:/
-
wrote on 3 Jul 2011, 15:05 last edited by
for instance :
@.arg("<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"</a>")@Do you need to translate this ?
@<a><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"</a>")@
you should put everything in one string except the parts you want translated. put them in the arg()
i suggest you look at my example and experiment with it. Try to understand it. Read the books chapter.
-
wrote on 3 Jul 2011, 15:25 last edited by
I got it but same problem..
@QString written = QString(tr("In random order%1")).arg(":\nLeon Vytanos <<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"</a>leon.check.me@gmail.com>\nAlex Solanos <<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"</a>alexsol.developer@gmail.com>");
@The book at that point doesn't say anything more than what you have already told me..
-
wrote on 3 Jul 2011, 15:45 last edited by
Now it's ok. It's your html syntax that's wrong.
-
wrote on 3 Jul 2011, 16:16 last edited by
It seems like the textbrowzer has a different type of html.. so i finally found a solution and it is:
@ QString written = QString("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" content="1" /><style type="text/css">p, li { white-space: pre-wrap; }</style></head><body font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"><p margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">%1%2").arg(tr("In random order")).arg(":</p><p margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span font-family:'Sans'; font-size:10pt;">Leon Vytanos <</span><a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;">leon.check.me@gmail.com</span></a><span font-family:'Sans'; font-size:10pt;">></span></p><p margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span font-family:'Sans'; font-size:10pt;">Alex Solanos <</span><a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;">alexsol.developer@gmail.com</span></a><span font-family:'Sans'; font-size:10pt;">></span></p></body></html>");
@But the
@ QString written = QString("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">@
part if i remove it there will be no problem, Should it be with or without this line?
13/19