Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with arg at QString.
QtWS25 Last Chance

Problem with arg at QString.

Scheduled Pinned Locked Moved General and Desktop
19 Posts 2 Posters 7.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    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)!

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      You cannot use tr with the + QString operator.

      You just use one string with several %1 %2 %3 arguments

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Leon
        wrote on last edited by
        #3

        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 errors

        error: 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]’

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          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));@

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Leon
            wrote on last edited by
            #5

            And what would you have done if there was a second argument?

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              @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.

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Leon
                wrote on last edited by
                #7

                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$

                1 Reply Last reply
                0
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #8

                  you can find a link to the free book here :

                  http://doc.qt.nokia.com/4.7/how-to-learn-qt.html

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Leon
                    wrote on last edited by
                    #9

                    Downloaded! What about the problem?

                    1 Reply Last reply
                    0
                    • EddyE Offline
                      EddyE Offline
                      Eddy
                      wrote on last edited by
                      #10

                      Hint : get rid of those "+" symbols in your string!
                      that's why you get those results as I explained already

                      Qt Certified Specialist
                      www.edalsolutions.be

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        Leon
                        wrote on last edited by
                        #11

                        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?

                        1 Reply Last reply
                        0
                        • EddyE Offline
                          EddyE Offline
                          Eddy
                          wrote on last edited by
                          #12

                          [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.

                          Qt Certified Specialist
                          www.edalsolutions.be

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            Leon
                            wrote on last edited by
                            #13

                            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(">");
                            @

                            1 Reply Last reply
                            0
                            • EddyE Offline
                              EddyE Offline
                              Eddy
                              wrote on last edited by
                              #14

                              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.

                              Qt Certified Specialist
                              www.edalsolutions.be

                              1 Reply Last reply
                              0
                              • L Offline
                                L Offline
                                Leon
                                wrote on last edited by
                                #15

                                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

                                :/

                                1 Reply Last reply
                                0
                                • EddyE Offline
                                  EddyE Offline
                                  Eddy
                                  wrote on last edited by
                                  #16

                                  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.

                                  Qt Certified Specialist
                                  www.edalsolutions.be

                                  1 Reply Last reply
                                  0
                                  • L Offline
                                    L Offline
                                    Leon
                                    wrote on last edited by
                                    #17

                                    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..

                                    1 Reply Last reply
                                    0
                                    • EddyE Offline
                                      EddyE Offline
                                      Eddy
                                      wrote on last edited by
                                      #18

                                      Now it's ok. It's your html syntax that's wrong.

                                      Qt Certified Specialist
                                      www.edalsolutions.be

                                      1 Reply Last reply
                                      0
                                      • L Offline
                                        L Offline
                                        Leon
                                        wrote on last edited by
                                        #19

                                        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?

                                        1 Reply Last reply
                                        0

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved