Problem with arg at QString.
-
What am i doing wrong here?
@ 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</span></a>").arg("leon.check.me@gmail.com") + ">\nAlex Solanos <" + ("<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"<span>%1</span></a>").arg("alexsol.developer@gmail.com") + ">");
@I kwow the "(" is wrong but i am not familiar with arg..
I am trying to do this..
!http://img35.imageshack.us/img35/6444/screenshot2psv.png(Screenshot)!
-
Yes but the part i want to be translateble is only the "In random order" text..
Even if i change the second %1 to %2 i have some errorserror: request for member ‘arg’ in ‘("<a ><span font-family:'Sans'; font-size:10pt; text-decoration: underline; color:#ff5500;"<span>%1</span></a>")’, which is of non-class type ‘const char [154]’
-
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));@
-
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$
-
you can find a link to the free book here :
-
[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.
-
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(">");
@ -
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
:/
-
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.
-
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..
-
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?