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. Localization of text messages during main() function
Forum Update on Tuesday, May 27th 2025

Localization of text messages during main() function

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 328 Views 2 Watching
  • 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.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    Sometimes errors will occur before the main window is shown, or possibly warnings which can be shown just after calling QMainWindow::show(). However, I have not yet been able to show localized error messages except within the body of a function belonging to a descendent of QObject. I can translate them im QtLinguist, but only the original language is shown.

    Is there a well-known workaround for this? I suppose I could make them member variables in my main window class and defer showing the messages until after the main window opens, but maybe there is another way?

    JonBJ Pablo J. RoginaP 2 Replies Last reply
    0
    • R Robert Hairgrove

      Sometimes errors will occur before the main window is shown, or possibly warnings which can be shown just after calling QMainWindow::show(). However, I have not yet been able to show localized error messages except within the body of a function belonging to a descendent of QObject. I can translate them im QtLinguist, but only the original language is shown.

      Is there a well-known workaround for this? I suppose I could make them member variables in my main window class and defer showing the messages until after the main window opens, but maybe there is another way?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Robert-Hairgrove
      Assuming what you say about QObject is correct (I don't know), you don't have to wait for the declaration/creation/showing of QMainWindow to use that. For example, you might put up a QDialog before/without even having a QMainWindow. So that cannot be the issue,

      1 Reply Last reply
      0
      • R Robert Hairgrove

        Sometimes errors will occur before the main window is shown, or possibly warnings which can be shown just after calling QMainWindow::show(). However, I have not yet been able to show localized error messages except within the body of a function belonging to a descendent of QObject. I can translate them im QtLinguist, but only the original language is shown.

        Is there a well-known workaround for this? I suppose I could make them member variables in my main window class and defer showing the messages until after the main window opens, but maybe there is another way?

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @Robert-Hairgrove you can install a QTranslator and set the desired language even in main.cpp see this example...

        #include <QApplication>
        #include <QPushButton>
        #include <QTranslator>
        
        int main(int argc, char *argv[])
        {
            QApplication app(argc, argv);
        
            QTranslator translator;
            translator.load("hellotr_la");
            app.installTranslator(&translator);
        
            QPushButton hello(QPushButton::tr("Hello world!"));
            hello.resize(100, 30);
            hello.show();
        
            return app.exec();
        }
        

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        3
        • R Offline
          R Offline
          Robert Hairgrove
          wrote on last edited by
          #4

          Thanks ... the problem was that my translations were being updated to a different location. Now it is working!

          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