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. Dynamic Language Change
Forum Updated to NodeBB v4.3 + New Features

Dynamic Language Change

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 677 Views
  • 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.
  • A Offline
    A Offline
    Alpkan
    wrote on last edited by
    #1

    I couldn't fix the issue how i will fix these warnings

    resim_2021-03-25_111330.png
    resim_2021-03-25_111347.png

    resim_2021-03-25_111414.png
    9462574e-76a4-407c-96c9-84cda5975310-image.png

    J.HilkJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      Please post code instead screenshots.

      QLabel ctor wants a QWidget-derived class, your MyWidget does not derive from QWidget but from QObject.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      6
      • A Alpkan

        I couldn't fix the issue how i will fix these warnings

        resim_2021-03-25_111330.png
        resim_2021-03-25_111347.png

        resim_2021-03-25_111414.png
        9462574e-76a4-407c-96c9-84cda5975310-image.png

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @Alpkan in addition to what @Christian-Ehrlicher said, QCoreApplication does not support QWidgets, use at least QApplication instead (or QGuiApplication)

        therefore I think your pro file is probably missing important QT += linkages too


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        4
        • Christian EhrlicherC Christian Ehrlicher

          Please post code instead screenshots.

          QLabel ctor wants a QWidget-derived class, your MyWidget does not derive from QWidget but from QObject.

          A Offline
          A Offline
          Alpkan
          wrote on last edited by
          #4

          @Christian-Ehrlicher
          resim_2021-03-25_130359.png

          QT -= gui
          QT += core
          QT += widgets

          I understand your point but i am trying do without qapplication

          KroMignonK 1 Reply Last reply
          0
          • A Alpkan

            @Christian-Ehrlicher
            resim_2021-03-25_130359.png

            QT -= gui
            QT += core
            QT += widgets

            I understand your point but i am trying do without qapplication

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #5

            @Alpkan said in Dynamic Language Change:

            I understand your point but i am trying do without qapplication

            This is a non sense, if you want to use QWidget you need a QApplication or QGuiApplication

            QApplication specializes QGuiApplication with some functionality needed for QWidget-based applications. It handles widget specific initialization, finalization.

            For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any given time. For non-QWidget based Qt applications, use QGuiApplication instead, as it does not depend on the QtWidgets library.

            Some GUI applications provide a special batch mode ie. provide command line arguments for executing tasks without manual intervention. In such non-GUI mode, it is often sufficient to instantiate a plain QCoreApplication to avoid unnecessarily initializing resources needed for a graphical user interface. The following example shows how to dynamically create an appropriate type of application instance:

            => https://doc.qt.io/qt-5/qapplication.html#details

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply
            1
            • A Offline
              A Offline
              Alpkan
              wrote on last edited by
              #6

              so there is a code which is

              MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
              {
              titleLabel = new QLabel(this);
              okPushButton = new QPushButton(this);
              // Fire the LanguageChange event - the event handler will set the texts:
              QEvent languageChangeEvent(QEvent::LanguageChange);
              QCoreApplication::sendEvent(this, &languageChangeEvent);
              }

              void MyWidget::changeEvent(QEvent *event)
              {
              if (event->type() == QEvent::LanguageChange) {
              titleLabel->setText(tr("Document Title"));
              okPushButton->setText(tr("&OK"));
              } else {
              QWidget::changeEvent(event);
              }
              }
              *
              this code is written for dynamic language change
              if is it possible use that code can u explain to me than i will do it if it is not what is true way

              J.HilkJ 1 Reply Last reply
              0
              • A Alpkan

                so there is a code which is

                MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
                {
                titleLabel = new QLabel(this);
                okPushButton = new QPushButton(this);
                // Fire the LanguageChange event - the event handler will set the texts:
                QEvent languageChangeEvent(QEvent::LanguageChange);
                QCoreApplication::sendEvent(this, &languageChangeEvent);
                }

                void MyWidget::changeEvent(QEvent *event)
                {
                if (event->type() == QEvent::LanguageChange) {
                titleLabel->setText(tr("Document Title"));
                okPushButton->setText(tr("&OK"));
                } else {
                QWidget::changeEvent(event);
                }
                }
                *
                this code is written for dynamic language change
                if is it possible use that code can u explain to me than i will do it if it is not what is true way

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @Alpkan It's not, changeEvent has its root in QWidget not in QObject you can't simply name a function changeEvent in a non QWidget based class and expect it to behave like a QWidget.

                I think you want to notify your QObject based classes that a new language has been set and they should change their strings, right?

                You'll have to find a way to notify them yourself. There are countless ways, but - afaik - no ready made Qt ways


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                2

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved