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. QT_TRANSLATE_NOOP translation not triggered?
Forum Updated to NodeBB v4.3 + New Features

QT_TRANSLATE_NOOP translation not triggered?

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

    Hi,
    I'm having few static variables defined in an Object using QT_TRANSLATE_NOOP.

    in header:
        static const char *sFolderMonitoringName;
        static const char *sQuickJobName;
    
    
    in cpp:
    const char *NgPost::sFolderMonitoringName = QT_TRANSLATE_NOOP("NgPost", "Auto Posting");
    const char *NgPost::sQuickJobName         = QT_TRANSLATE_NOOP("NgPost", "Quick Post");
    

    So then in my MainWindow::changeEvent(QEvent *event) that is triggered each time a translator is installed, I'm trying to use those static members to some texts but it's not working...
    Any idea why?

    void MainWindow::changeEvent(QEvent *event)
    {
        if(event)
        {
            QTabBar *tabBar = _ui->postTabWidget->tabBar();
            switch(event->type()) {
            // this event is send if a translator is loaded
            case QEvent::LanguageChange:
                _ui->retranslateUi(this);
    
                tabBar->setTabText(0, tr(_ngPost->sQuickJobName));
                tabBar->setTabText(1, tr(_ngPost->sFolderMonitoringName));
    ...
    

    Of course their text are in the ts file, and I've provided a translation in other languages.
    If I were not using those static member variable but somethink like

    tabBar->setTabText(0, tr("my title"));
    

    It is working...

    I'm using QT_TRANSLATE_NOOP in other places and it's working perfectly.
    Am I missing something?
    Cheers

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mbruel said in QT_TRANSLATE_NOOP translation not triggered?:

      Am I missing something?

      The namespace is wrong, you're calling tr from the MainWindow.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • mbruelM Offline
        mbruelM Offline
        mbruel
        wrote on last edited by mbruel
        #3

        oh it has to be on the same namespace... I thought it would pick it up from the object being used...
        Cheers man, I just did some accessors and it's working perfectly!

        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