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. Reading strings for labels from .qrc
Forum Updated to NodeBB v4.3 + New Features

Reading strings for labels from .qrc

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.5k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    ad5xj
    wrote on last edited by
    #1

    There does not seem to be an obvious answer here so I submit this for the forum.

    I wish to load the English text for labels from a .qrc file in a similar way as Windows uses rcc files in VB. However, there is no clear indication in the docs as to how to do this. You can store a file name in the .qrc that can then read in text from the file (using the URL name). But, that is not the same.

    How do you store label text in a .qrc then use that text for a label ( e.g. label.setText(tr(<loaded text>) ).

    The resource creator only seems to allow file names. Seems like a newbie question but there it is.

    Ken AD5XJ

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you thinking about translating your application ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ad5xj
        wrote on last edited by
        #3

        Yes that is a possibility using tr().

        Ken AD5XJ

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then have a look at the Qt Linguist Manual, it explains how to translate Qt applications

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ad5xj
            wrote on last edited by
            #5

            This thread is not about translation or i18.

            Ken AD5XJ

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              qrc is only there to embed files in your application

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                ad5xj
                wrote on last edited by
                #7

                Then what is the point. I mean, the file URL could be included in the source as constant strings without the need for the .qrc at all. QImage, QIcon, and QPixmap all allow use of the url() idiom.

                If all it does is load file names what is the point?

                Ken AD5XJ

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  No that's not all, the goal of the qrc is to build these file directly in your application.

                  Have a look at the "resources":http://qt-project.org/doc/qt-5.0/qtcore/resources.html documentation.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dbzhang800
                    wrote on last edited by
                    #9

                    Hi, take a look at the rcc generated files qrc_xxxx.cpp, you can find all the magic behind the .qrc file.

                    [quote author="ad5xj" date="1375134174"]Then what is the point. I mean, the file URL could be included in the source as constant strings without the need for the .qrc at all. QImage, QIcon, and QPixmap all allow use of the url() idiom.

                    If all it does is load file names what is the point?[/quote]

                    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