How to change a QMenu text from english to russian by clicking a button

Please consider we have a menu which has text set "MyMenu" and I want to change the menu text by clicking a button in the same widget from "MyMenu" to "МойМеню". Could you bring a code snippet please for that operation?


Have a look at "Dynamic Translation",

void MyWidget::changeEvent(QEvent *event)
    if (e->type() == QEvent::LanguageChange)
        titleLabel->setText(tr("Document Title"));

        // You could also use : retranslateUi(QWidget*);

This will be helpful to you as well :

Basically, when you call : qApp->installTranslator(MyAppTranslator) it will create a QEvent::LanguageChange.

So, provide a simple QComboBox with English/Russian, and when the selected language changes, call qApp->installTranslator(MyAppTranslator);. Then make sure your buttons are properly set up in changeEvent, and that's it !

Hope it helps a bit !

int main(int argc, char *argv[])

    QApplication app(argc, argv);

    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));//this is the solution

And in the code you can dynamically change the strings if you set them from the begining by using tr() function [tr("your text")].

Need Your Help

error (261, -1003) android error in audio play

android audio

I am trying to play an audio on click of an Image. When I run the app and click on the Image I get below error in the console: