How to load translation for static library widget



  • Hi,

    I've two sub-projects the first one is a widget built as static library while the second is an application uses that library.

    THE PROBLEM: I don't know how to load translation for the used widget... May I get some help from you?

    TARGET = WidgetKeyboard
    TEMPLATE = lib
    CONFIG += staticlib
    DESTDIR = bin
    
    greaterThan(QT_MAJOR_VERSION, 4) {
        QT += widgets multimedia
    }
    
    unix {
        target.path = /usr/lib
        INSTALLS += target
    }
    
    SOURCES += \
        widgetkeyboard.cpp \
        qkeypushbutton.cpp
    
    HEADERS += \
        qkeypushbutton.h \
        widgetkeyboard.h
    
    TRANSLATIONS += \
        i18n/WidgetKeyboard_ar.ts \
        i18n/WidgetKeyboard_de.ts \
        i18n/WidgetKeyboard_en.ts \
        i18n/WidgetKeyboard_fr.ts \
        i18n/WidgetKeyboard_it.ts \
        i18n/WidgetKeyboard_ru.ts
    
    RESOURCES += \
        languages.qrc \
        resources.qrc
    
    OTHER_FILES += \
        i18n/*.ts
    
    TARGET = Tester
    TEMPLATE = app
    
    INCLUDEPATH += ../WidgetKeyboard
    LIBS += -L../WidgetKeyboard/bin -lWidgetKeyboard
    
    greaterThan(QT_MAJOR_VERSION, 4) {
        QT += widgets multimedia
    }
    
    SOURCES += main.cpp \
        tester.cpp \
        examplemyfocus.cpp
    
    HEADERS += tester.h \
        examplemyfocus.h
    
    FORMS += tester.ui
    
    TRANSLATIONS += \
        i18n/tester_it.ts \
        i18n/tester_ru.ts \
        i18n/tester_en.ts \
        i18n/tester_de.ts \
        i18n/tester_fr.ts \
        i18n/tester_ar.ts
    
    OTHER_FILES += \
        i18n/*.ts
    
    RESOURCES += \
        resources.qrc
    

    I load the translation using this snippet:

    void Tester::on_listWidget_itemClicked(QListWidgetItem *item)
    {
        QLocale             *local;
        QString             newLang = item->text();
    
        if (newLang == "French")
            local = new QLocale(QLocale::French);
        else if (newLang == "Russian")
            local = new QLocale(QLocale::Russian);
        else if (newLang == "German")
            local = new QLocale(QLocale::German);
        else if (newLang == "Italian")
            local = new QLocale(QLocale::Italian);
        else if (newLang == "English")
            local = new QLocale(QLocale::English);
        else if (newLang == "Arabic")
            local = new QLocale(QLocale::Arabic);
        else
            local = new QLocale();
        //FIXME Unable to load translation for WidgetKeyboard!
        if (myTranslator->load(*local, QLatin1String("tester"), QLatin1String("_"), QLatin1String(":/i18n")))
            qApp->installTranslator(myTranslator);
        else
            qDebug("Failed to load a translation for QT in your local language");
    }
    

    You can get full source code from here: https://github.com/mbnoimi/VirtualKeyboard



  • @mbnoimi

    hi,
    theoretically if your lib is static (e.g. *.a or *.lib in win) that will be linked alongside the application that is using the lib.
    Then, just use QApplication::translate(...) with the correct context and it will work.



  • @AlterX

    theoretically if your lib is static (e.g. *.a or *.lib in win) that will be linked alongside the application that is using the lib.
    Then, just use QApplication::translate(...) with the correct context and it will work.

    Thanks, but this is not related to my question!
    I already successfully created translation for the library but I don't know how to load it when I call the widget


  • Lifetime Qt Champion

    Hi,

    You can use QTranslator like shown in the documentation. The fact that you don't do it in main is irrelevant. The only thing that you must ensure is that your widgets handle dynamic translation properly.



  • @SGaist said:

    You can use QTranslator like shown in the documentation. The fact that you don't do it in main is irrelevant. The only thing that you must ensure is that your widgets handle dynamic translation properly.

    I didn't mention calling from main() !

    My question is quite simple. How can I load *.qm from static library resource? as you can see below I can load *.qm easily from current project resource by using ":/"

    myTranslator->load(*local, QLatin1String("tester"), QLatin1String("_"), QLatin1String(":/i18n"))
    

    I aim to load translation from static library to be able to apply multiple translations as mentioned in QTranslator doc


  • Qt Champions 2016

    Hi
    Maybe try

    QDirIterator it(":", QDirIterator::Subdirectories);
        while (it.hasNext()) {
            qDebug() << it.next();
        }
    

    to have a look how the files are named in the running exe to to verify
    that they are indeed under ":/i18n" and paths are as you expect.


  • Qt Champions 2016

    @mbnoimi

    My question is quite simple. How can I load *.qm from static library resource? as you can see below I can load *.qm easily from current project resource by using ":/"

    You're asking the wrong question. Actually @SGaist and @AlterX have provided valuable feedback and you'd be wise to take it into account. I peeked into your repository and I'm pretty sure you're creating your translator wrongly. Did you notice this warning: "Note that the translator must be created before the application's widgets." in the documentation?

    Kind regards.


  • Lifetime Qt Champion

    To add to @kshegunov , the note concerns the use of QTranslator shown in the example i.e. setup of the language at application startup and no support of dynamic translations.


  • Qt Champions 2016

    @SGaist
    Oh, yes, you're surely correct I forgot to check for the changeEvent() override in his code :S Still I don't see anything wrong with the translation loading by itselt.



  • @SGaist said:

    To add to @kshegunov , the note concerns the use of QTranslator shown in the example i.e. setup of the language at application startup and no support of dynamic translations.

    How the application doesn't support dynamic translations? Take a look into this line it calls changeEvent and if you run the app. you'll find that Tester loads the translations dynamically correctly while it doesn't call translations for static library widget because I don't know how to do it!



  • I tried to use Q_INIT_RESOURCE as mentioned in this line but unfortunately it makes things worst.


  • Qt Champions 2016

    @mbnoimi

    How the application doesn't support dynamic translations?

    He was referring to the note in the documentation I was citing, and was explaining that it is only relevant when there is no support for dynamic translation.

    it doesn't call translations for static library widget because I don't know how to do it!

    You do it, like you're doing it now. Here's the thing, a static library is nothing more then a bunch of .obj files put together. Linking a static library just includes them into your application's binary. This means, that there is nothing different between widgets that come from a static library and these declared in your application (see @AlterX's comment, he mentioned that). That's why I said you're asking the wrong question. Your translation loading looks perfectly fine to me, and it has nothing to do with static or dynamic libraries - you need to look elsewhere to solve the problem. Do you have any output in the creator's windows that might suggest your translation is not loaded? Do you get the "Failed to load a translation for QT in your local language" message printed?

    I tried to use Q_INIT_RESOURCE as mentioned in this line but unfortunately it makes things worst.

    Yes you should do that for all the resources in your static library. But according to this it should be placed in the beginning of main().

    Kind regards.



  • @kshegunov

    Do you have any output in the creator's windows that might suggest your translation is not loaded?

    No

    Do you get the "Failed to load a translation for QT in your local language" message printed?

    No. I get Failed to load translation from static library error message!



  • @kshegunov said:

    according to this it should be placed in the beginning of main().

    I did that... still get same behavior.


  • Qt Champions 2016

    Hello,
    Something is amiss here, let's take it from the top. You said that you get the "Failed to load a translation for QT in your local language" message, but this message is to be shown when this fails:

        myTranslator->load(*local, QLatin1String("tester"), QLatin1String("_"), QLatin1String(":/i18n"))
    

    This particular line is in your application and tries to load an application translation, where does a static library resource come in play here? Could you tell what is the current language you're using and its iso code (you could use QLocale::language() and QLocale::languageToString), and make sure there's a matching translation file?

    Kind regards.



  • @kshegunov said:

    Hello,
    Something is amiss here, let's take it from the top. You said that you get the "Failed to load a translation for QT in your local language" message, but this message is to be shown when this fails: myTranslator->load(*local, QLatin1String("tester"), QLatin1String("_"), QLatin1String(":/i18n"))

    I didn't say that!
    I said I get Failed to load translation from static library which points to myTranslator->load(":/languages/arabic") failure!

    where does a static library resource come in play here?

    As I mentioned above this line suppose to load translation from static library's resource

    Could you tell what is the current language you're using and its iso code

    English; en_US


  • Qt Champions 2016

    @mbnoimi

    I didn't say that!
    I said I get Failed to load translation from static library

    Indeed you did, it's my mistake, sorry.

    which points to myTranslator->load(":/languages/arabic") failure!

    Could you verify that this file is available? For example what does QFile::exists(":/languages/arabic") return, true or false? If the file exists then the problem is with the actual loading, if the file is not found, then I guess there's a problem with the resource initialization.

    Kind regards.



  • @kshegunov said:

    Could you verify that this file is available? For example what does QFile::exists(":/languages/arabic") return, true or false?

    I get true

    If the file exists then the problem is with the actual loading, if the file is not found, then I guess there's a problem with the resource initialization.

    After reviewing the project I discovered there are two "resources.qrc" the first one in the static library and the other in tester app. so I supposed this maybe makes Qt confused so I renamed one of them to a different name but unfortunately I still get same result.



  • @mrjj said:

    QDirIterator it(":", QDirIterator::Subdirectories);
        while (it.hasNext()) {
            qDebug() << it.next();
        }
    

    to have a look how the files are named in the running exe to to verify
    that they are indeed under ":/i18n" and paths are as you expect.

    I got this output:

    Failed to load translation from static library
    ":/qt-project.org"
    ":/qt-project.org/qmime"
    ":/qt-project.org/qmime/freedesktop.org.xml"
    ":/qt-project.org/styles"
    ":/qt-project.org/styles/commonstyle"
    ":/qt-project.org/styles/commonstyle/images"
    ":/qt-project.org/styles/commonstyle/images/networkdrive-16.png"
    ":/qt-project.org/styles/commonstyle/images/networkdrive-32.png"
    ":/qt-project.org/styles/commonstyle/images/dvd-16.png"
    ":/qt-project.org/styles/commonstyle/images/cdr-16.png"
    ":/qt-project.org/styles/commonstyle/images/up-16.png"
    ":/qt-project.org/styles/commonstyle/images/up-32.png"
    ":/qt-project.org/styles/commonstyle/images/dvd-32.png"
    ":/qt-project.org/styles/commonstyle/images/cdr-32.png"
    ":/qt-project.org/styles/commonstyle/images/left-32.png"
    ":/qt-project.org/styles/commonstyle/images/stop-32.png"
    ":/qt-project.org/styles/commonstyle/images/file-16.png"
    ":/qt-project.org/styles/commonstyle/images/down-16.png"
    ":/qt-project.org/styles/commonstyle/images/stop-24.png"
    ":/qt-project.org/styles/commonstyle/images/left-16.png"
    ":/qt-project.org/styles/commonstyle/images/down-32.png"
    ":/qt-project.org/styles/commonstyle/images/file-32.png"
    ":/qt-project.org/styles/commonstyle/images/dirlink-32.png"
    ":/qt-project.org/styles/commonstyle/images/diropen-32.png"
    ":/qt-project.org/styles/commonstyle/images/diropen-16.png"
    ":/qt-project.org/styles/commonstyle/images/cleartext-16.png"
    ":/qt-project.org/styles/commonstyle/images/dirlink-16.png"
    ":/qt-project.org/styles/commonstyle/images/networkdrive-128.png"
    ":/qt-project.org/styles/commonstyle/images/media-volume-muted-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-open-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-apply-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-apply-16.png"
    ":/qt-project.org/styles/commonstyle/images/fonttruetype-16.png"
    ":/qt-project.org/styles/commonstyle/images/newdirectory-128.png"
    ":/qt-project.org/styles/commonstyle/images/filecontents-128.png"
    ":/qt-project.org/styles/commonstyle/images/floppy-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-delete-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-delete-32.png"
    ":/qt-project.org/styles/commonstyle/images/harddrive-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-clear-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-close-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-clear-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-close-16.png"
    ":/qt-project.org/styles/commonstyle/images/dirclosed-128.png"
    ":/qt-project.org/styles/commonstyle/images/trash-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-apply-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-yes-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-yes-32.png"
    ":/qt-project.org/styles/commonstyle/images/fontbitmap-16.png"
    ":/qt-project.org/styles/commonstyle/images/newdirectory-32.png"
    ":/qt-project.org/styles/commonstyle/images/dirclosed-32.png"
    ":/qt-project.org/styles/commonstyle/images/newdirectory-16.png"
    ":/qt-project.org/styles/commonstyle/images/dirclosed-16.png"
    ":/qt-project.org/styles/commonstyle/images/up-128.png"
    ":/qt-project.org/styles/commonstyle/images/media-pause-32.png"
    ":/qt-project.org/styles/commonstyle/images/media-pause-16.png"
    ":/qt-project.org/styles/commonstyle/images/cdr-128.png"
    ":/qt-project.org/styles/commonstyle/images/dvd-128.png"
    ":/qt-project.org/styles/commonstyle/images/media-volume-16.png"
    ":/qt-project.org/styles/commonstyle/images/harddrive-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-16.png"
    ":/qt-project.org/styles/commonstyle/images/harddrive-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-hover-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-32.png"
    ":/qt-project.org/styles/commonstyle/images/viewdetailed-128.png"
    ":/qt-project.org/styles/commonstyle/images/fusion_groupbox.png"
    ":/qt-project.org/styles/commonstyle/images/right-128.png"
    ":/qt-project.org/styles/commonstyle/images/fileinfo-16.png"
    ":/qt-project.org/styles/commonstyle/images/filelink-16.png"
    ":/qt-project.org/styles/commonstyle/images/filelink-32.png"
    ":/qt-project.org/styles/commonstyle/images/fileinfo-32.png"
    ":/qt-project.org/styles/commonstyle/images/dirlink-128.png"
    ":/qt-project.org/styles/commonstyle/images/media-seek-forward-16.png"
    ":/qt-project.org/styles/commonstyle/images/media-seek-forward-32.png"
    ":/qt-project.org/styles/commonstyle/images/diropen-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-help-128.png"
    ":/qt-project.org/styles/commonstyle/images/viewdetailed-16.png"
    ":/qt-project.org/styles/commonstyle/images/viewdetailed-32.png"
    ":/qt-project.org/styles/commonstyle/images/media-seek-backward-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-ok-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-no-128.png"
    ":/qt-project.org/styles/commonstyle/images/media-seek-backward-32.png"
    ":/qt-project.org/styles/commonstyle/images/refresh-32.png"
    ":/qt-project.org/styles/commonstyle/images/refresh-24.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-save-128.png"
    ":/qt-project.org/styles/commonstyle/images/viewlist-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-yes-128.png"
    ":/qt-project.org/styles/commonstyle/images/computer-32.png"
    ":/qt-project.org/styles/commonstyle/images/computer-16.png"
    ":/qt-project.org/styles/commonstyle/images/parentdir-32.png"
    ":/qt-project.org/styles/commonstyle/images/parentdir-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-16.png"
    ":/qt-project.org/styles/commonstyle/images/media-play-16.png"
    ":/qt-project.org/styles/commonstyle/images/desktop-16.png"
    ":/qt-project.org/styles/commonstyle/images/media-stop-16.png"
    ":/qt-project.org/styles/commonstyle/images/desktop-32.png"
    ":/qt-project.org/styles/commonstyle/images/media-play-32.png"
    ":/qt-project.org/styles/commonstyle/images/down-128.png"
    ":/qt-project.org/styles/commonstyle/images/media-stop-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-delete-128.png"
    ":/qt-project.org/styles/commonstyle/images/media-skip-backward-32.png"
    ":/qt-project.org/styles/commonstyle/images/media-skip-backward-16.png"
    ":/qt-project.org/styles/commonstyle/images/fusion_arrow.png"
    ":/qt-project.org/styles/commonstyle/images/viewlist-16.png"
    ":/qt-project.org/styles/commonstyle/images/viewlist-32.png"
    ":/qt-project.org/styles/commonstyle/images/file-128.png"
    ":/qt-project.org/styles/commonstyle/images/floppy-32.png"
    ":/qt-project.org/styles/commonstyle/images/left-128.png"
    ":/qt-project.org/styles/commonstyle/images/floppy-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-no-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-ok-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-no-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-ok-16.png"
    ":/qt-project.org/styles/commonstyle/images/media-skip-forward-32.png"
    ":/qt-project.org/styles/commonstyle/images/media-skip-forward-16.png"
    ":/qt-project.org/styles/commonstyle/images/filelink-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-open-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-open-32.png"
    ":/qt-project.org/styles/commonstyle/images/fileinfo-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-help-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-help-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-save-16.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-save-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-down-16.png"
    ":/qt-project.org/styles/commonstyle/images/parentdir-128.png"
    ":/qt-project.org/styles/commonstyle/images/filecontents-32.png"
    ":/qt-project.org/styles/commonstyle/images/trash-32.png"
    ":/qt-project.org/styles/commonstyle/images/filecontents-16.png"
    ":/qt-project.org/styles/commonstyle/images/trash-16.png"
    ":/qt-project.org/styles/commonstyle/images/right-16.png"
    ":/qt-project.org/styles/commonstyle/images/right-32.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-clear-128.png"
    ":/qt-project.org/styles/commonstyle/images/standardbutton-close-128.png"
    ":/qt-project.org/styles/macstyle"
    ":/qt-project.org/styles/macstyle/images"
    ":/qt-project.org/styles/macstyle/images/toolbar-ext.png"
    ":/qt-project.org/styles/macstyle/images/dockdock-down-16.png"
    ":/qt-project.org/styles/macstyle/images/closedock-16.png"
    ":/qt-project.org/styles/macstyle/images/dockdock-16.png"
    ":/qt-project.org/styles/macstyle/images/closedock-down-16.png"
    ":/qt-project.org/styles/macstyle/images/toolbar-ext@2x.png"
    ":/qt-project.org/qmessagebox"
    ":/qt-project.org/qmessagebox/images"
    ":/qt-project.org/qmessagebox/images/qtlogo-64.png"
    ":/i18n"
    ":/i18n/tester_ar.qm"
    ":/i18n/tester_de.qm"
    ":/i18n/tester_fr.qm"
    ":/i18n/tester_en.qm"
    ":/i18n/tester_ru.qm"
    ":/i18n/tester_it.qm"
    ":/languages"
    ":/languages/i18n"
    ":/languages/i18n/WidgetKeyboard_fr.qm"
    ":/languages/i18n/WidgetKeyboard_ar.qm"
    ":/languages/i18n/WidgetKeyboard_de.qm"
    ":/languages/i18n/WidgetKeyboard_en.qm"
    ":/languages/i18n/WidgetKeyboard_it.qm"
    ":/languages/i18n/WidgetKeyboard_ru.qm"
    ":/images"
    ":/images/cut"
    ":/images/copy"
    ":/images/logo"
    ":/images/paste"
    ":/images/normalEcho"
    ":/images/passwdEcho"
    ":/sounds"
    ":/sounds/click.wav"
    QSoundEffect(pulseaudio): Error decoding source
    

  • Qt Champions 2016

    @mbnoimi
    What about loading like this:

        translator->load("arabic", ":/languages");
    

    And as a second suggestion: I think you should create another QTranslator object for the second translation file.

    Kind regards.



  • @kshegunov said:

    And as a second suggestion: I think you should create another QTranslator object for the second translation file.

    Thanks. This fixed Tester app. problem but it didn't fix the main problem (loading translation from static library) I still get this error message:

    Failed to load translation from static library


  • Qt Champions 2016

    @mbnoimi
    And have you tried the loading like this translator->load("arabic", ":/languages");, since you didn't comment on that?



  • @kshegunov said:

    @mbnoimi
    And have you tried the loading like this translator->load("arabic", ":/languages");, since you didn't comment on that?

    Didn't work :( I get same error message


  • Qt Champions 2016

    Can I ask some silly maybe ?
    The list shows
    :/i18n/tester_ar.qm

    There is no "arabic" under languages
    there is
    ":/languages/i18n/WidgetKeyboard_ar.qm"



  • @kshegunov said:

    And have you tried the loading like this translator->load("arabic", ":/languages");, since you didn't comment on that?

    I tried to use translator->load(":/languages/i18n/WidgetKeyboard_ar") instead. The error message disappeared ("Failed to load translation from static library") but the widget comes from the static library still appears in English!


  • Qt Champions 2016

    Silly question number 2.
    The test calls ui->retranslateUi(this);
    void Tester::changeEvent(QEvent *event)
    {
    if (event->type() == QEvent::LanguageChange) {
    ui->retranslateUi(this);
    } else
    QWidget::changeEvent(event);
    }
    But tester ui->retranslate() knows about the widgets from the library ?
    retranslateUi() just call all ->setText for elements inserted on the UI.
    How can it know about widgets in the Lib?
    Who calls widget_in_lib->setText?



  • @mrjj said:

    But tester ui->retranslate() knows about the widgets from the library ?
    retranslateUi() just call all ->setText for elements inserted on the UI.
    How can it know about widgets in the Lib?
    Who calls widget_in_lib->setText?

    Fair point. But as you can see from the code the widget in static library built manually not by using Qt Designer so retranslate doesn't exist and I don't know how to create an alternative to it :(


  • Qt Champions 2016

    @mbnoimi
    well for dynamic translation, meaning load translation AFTER keyboard been created would be to call
    void WidgetKeyBoard::createKeyboard(void) again.
    As it seems to be the only place with tr(text);
    retranslateUi() is very simple in all programs. it simply just sets the texts again
    and the tr function gets the new text from the active translation.
    Alternatively you need enum all widgets (in keyboard), get the text and re-set it via tr / directly look up trans text.
    But it can be messy if many types of Widgets as then u need to handle the "setText" for each.



  • @mrjj said:

    @mbnoimi
    well for dynamic translation, meaning load translation AFTER keyboard been created would be to call
    void WidgetKeyBoard::createKeyboard(void) again.

    I tried to call createKeyboard() once again as following but still gives same result although this function calls tr() so it suppose to do what you talked about!

    void Tester::changeEvent(QEvent *event)
    {
        if (event->type() == QEvent::LanguageChange) {
            ui->retranslateUi(this);
            myKeyboard->createKeyboard();
        } else
            QWidget::changeEvent(event);
    }
    

  • Qt Champions 2016

    Hi
    Maybe you can
    delete myKeyboard;
    myKeyboard = new Keyboard(this);
    as im not sure if calling createKeyboard() for same instance is 100% ok. (did not try it)

    Then there is the context thing.
    for mainwindow, its "mainwindow" (doh), but I do wonder about the translation that comes from static.

    Since they are linked into "main", I assume its context is the same as main (tester) but if the
    qm is different, it will not work.

    So open them (qms) in Linguist and check the context they were extracted as.

    then try with
    http://doc.qt.io/qt-5/qcoreapplication.html#translate

    To test a translation with that context and see if it does resolve.

    First then I would worry about tr working in createKeyboard()

    If I may say so.

    update:
    Context is "WidgetKeyBoard"
    So calling createKeyboard() should be in the right context as we are in that class.

    So testing with qcoreapplication.html#translate
    to see if all is loaded and happy.



  • Thank you guys, I'm no longer work on this project since Digia announcement.


  • Qt Champions 2016

    @mbnoimi
    Ok, why if I can ask?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.