title: How to change to tabButtons added dynamically on a TabBar in QML
body: <p>Lets suppose we add some <code>TabButton</code> using the <code>qml</code>javascript, with the line <code>tabBar.addItem</code> and as argument <code>tabButton.createObject</code>.</p>
  
  <p>Now what i want to do is if i change the language i want the text of the <code>TabButton</code> to change too.</p>
  
  <p>How can this be done?</p>
  
  <p>I know i can have on components (and i already have it working on a real app) a conection (that reacts to a signal) from a c++ class where we load the translations like this</p>
  
  <pre><code>Connections {
      target: qmlTranslator
      onLanguageChanged: {
        doSomething()
      }
  }
  </code></pre>
  
  <p>I'm not finding a way to have it work with this tabbuttons. I provide a simple code to illustrate what i have:</p>
  
  <pre><code>import QtQuick 2.7
  import QtQuick.Dialogs 1.2
  import QtQuick.Layouts 1.3
  import QtQuick.Controls 2.3
  import QtQuick.Window 2.3
  
  ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr("Tabbars")
  
      function assertCDataTabs () {
          var tabs = ["Config", "Devices", "IOs", "Sounders", "Zones"]
          for (var t in tabs) {
                      tabBar.addItem(tabButton.createObject(tabBar, { text: QT_TRANSLATE_NOOP("main",t), "font.pixelSize": 14  }))
          }
          backgroundHome.visible=false;
      }
  
      header: TabBar {
          id: tabBar
          opacity:0.8
      }
  
      Component {
          id: tabButton
          TabButton {
              font.pixelSize: 14
          }
      }
  
      StackLayout {
          id: content
          currentIndex: tabBar.currentIndex
          anchors.fill: parent
      }
  
      Component.onCompleted: {
          assertCDataTabs()
      }
  }
  </code></pre>
  
  <p>EDIT:
  Why does this not work?</p>
  
  <pre><code>Connections {
      target: qmlTranslator
      onLanguageChanged: {
          var _contentData = tabBar.contentData
          if(_contentData.length &gt; 0){
              for(var i=0;i&lt;_contentData.length;i++){
                  var textTrans = _contentData[i]['contentItem']['text']
                  tabBar.itemAt(i).text = qsTr(textTrans)
              }
          }
          }
      }
  </code></pre>
  
  <p>qmltranslator.cpp</p>
  
  <pre><code>#include "qmltranslator.h"
  #include &lt;QApplication&gt;
  #include &lt;QDebug&gt;
  #include &lt;QDir&gt;
  
  QmlTranslator::QmlTranslator(QQmlEngine *engine)
  {
      _translator = new QTranslator(this);
      _engine = engine;
  }
  
  void QmlTranslator::selectLanguage(QString language)
  {
      // working folder
      QDir dir = QDir(qApp-&gt;applicationDirPath()).absolutePath();
   //    #ifdef Q_OS_MACOS // crutch for Mac OS
   //    dir.cdUp();
   //    dir.cdUp();
   //    dir.cdUp();
   //    #endif
   //    qDebug() &lt;&lt; dir.path();
      QString languagesArray[] = { "en", "pt", "es", "br", "de", "dk", "fi", "fr", "it", "lt", "no", "ro", "tr", "hu" };
  
      for(int i=0;i&lt;languagesArray-&gt;length();i++){
          if(languagesArray[i] != language){
              _translator-&gt;load(":/translations/" + QString("Lang-%1").arg(languagesArray[i]));
              qApp-&gt;removeTranslator(_translator);
          }
      }
  
      if (!_translator-&gt;load(":/translations/" + QString("Lang-%1").arg(language)))
      {
          qDebug() &lt;&lt; "Failed to load translation file, falling back to English";
      }
  
      qApp-&gt;installTranslator(_translator);
  
      _engine-&gt;retranslate();
      emit languageChanged();
  }
  </code></pre>
  
  <p>qmltranslator.h</p>
  
  <pre><code>#ifndef QMLTRANSLATOR_H
  #define QMLTRANSLATOR_H
  
  #include &lt;QObject&gt;
  #include &lt;QTranslator&gt;
  #include &lt;QQmlEngine&gt;
  
  class QmlTranslator : public QObject
  {
      Q_OBJECT
  
  public:
      QmlTranslator(QQmlEngine *engine);
      Q_INVOKABLE void selectLanguage(QString language);
  
  signals:
      void languageChanged();
  
  private:
      QTranslator *_translator;
      QQmlEngine *_engine;
  };
  
  
  #endif // QMLTRANSLATOR_H
  </code></pre>
  
  <p>on the main to have it acessible through qml</p>
  
  <pre><code>QQmlApplicationEngine engine;
  QmlTranslator qmlTranslator(&amp;engine);
  // and register it as a context in Qml layer
  engine.rootContext()-&gt;setContextProperty("qmlTranslator", &amp;qmlTranslator);
  engine.load(QUrl(QLatin1String("qrc:/main.qml")));
  </code></pre>