Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:33:08+00:00 2026-05-26T13:33:08+00:00

I redefined QApplication class and add switchLanguage slot and i want to switch language

  • 0

I redefined QApplication class and add switchLanguage slot and i want to switch language when i press but1. main_ru.qm and main_de.qm is normal, 100% working. But language don’t change when i press button

// main.cpp
#include <QtGui>
#include "qmyapp.h"

int main( int argc, char** argv )
{
    QMyApp app( argc, argv );
    QTranslator translator;
    // задаём файл перевода и директорию
    translator.load( "main_ru.qm", "." );
    app.installTranslator( &translator );
    QWidget wgt;
    QLabel *lbl = new QLabel( QObject::tr( "Hello" ) );
    QPushButton *but1 = new QPushButton( "1" );    
    QVBoxLayout *vbox = new QVBoxLayout;
    QObject::connect( but1, SIGNAL( clicked() ), &app, SLOT( switchLanguage() ) );    
    vbox->addWidget( lbl );
    vbox->addWidget( but1 );
    wgt.setLayout( vbox );
    wgt.show();
    return app.exec();
}

// qmyapp.h
#ifndef QMYAPP_H
#define QMYAPP_H

#include <QApplication>
#include <QtGui>

class QMyApp : public QApplication
{
    Q_OBJECT
public:
    QMyApp(int &argc, char **argv ) : QApplication ( argc, argv ) {}
public slots:
    void switchLanguage( )
    {
        QTranslator* translator = new QTranslator();
        translator->load( "main_de.qm", "." );
        this->installTranslator( translator );
    }
};

#endif // QMYAPP_H
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:33:08+00:00Added an answer on May 26, 2026 at 1:33 pm

    You need to call translate again after installing new translations. So after you call switchLangauge() you need to call QObject::tr() once again in whatever context it was used before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to call a redefined private method from an abstract parent class. I
I get numerous method redefined warnings while running an application under Merb 0.9.3. Of
I want to redefine the required attribute for a field in a clean method
I want to redefine several arithmetic operators in Haskell in order to make them
I want to redefine the \part* command so that it automatically adds a contents
Is there any way to redefine a class or some of its methods without
I understand overriding a method/function redefines its implementation in the derived class from its
If your coworker opens (monkeypatches) a class in Ruby and redefines some important functionality
To specialize a class template, one has to redefine all of the member functions
I have a Java application and I want to implement an Undo/Redo option. the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.