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. QCoreApplication::translate() versus QObject::tr() versus tr()
Forum Updated to NodeBB v4.3 + New Features

QCoreApplication::translate() versus QObject::tr() versus tr()

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 928 Views 2 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    Up to now I have used tr() macro for translatable string in classes that derived from QObject and used the QOBJECT macro. For non QObject code I have used QCoreApplication::translate() specifying a "context".

    I just now encountered code that uses QObject::tr() - does that effectively do the same as QCoreApplication::translate with a context of "QObject"?

    Thanks
    David

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      does that effectively do the same as QCoreApplication::translate with a context of "QObject"?

      Yes. Q_OBJECT macro adds a static tr function to the class that just calls QMetaObject::tr from the staticMetaObject of that class and that calls QCoreApplication::translate() with the class name as the context, so calling static QObject::tr will have a context of "QObject".

      1 Reply Last reply
      1
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        Thanks Chris

        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