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. Wrong text display : Qt 5.14 only
QtWS25 Last Chance

Wrong text display : Qt 5.14 only

Scheduled Pinned Locked Moved Solved General and Desktop
qmlqt 5.14text corruptioncharacter encod
18 Posts 7 Posters 2.5k 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.
  • U Offline
    U Offline
    Ulysse
    wrote on 20 Mar 2020, 14:39 last edited by Ulysse
    #1

    TLDR :
    Font file needs to be loaded before the creation of objects that use them
    In my case :

    int main(int argc, char* argv[]){
        // [...]
        QApplication a(argc, argv);
        QFontDatabase::addApplicationFont(":/police/roboto.ttf");
        MainWindow w;
        // [...]
    }
    

    Doing the other way around can cause the bug (could not reproduce the bug in a minimal example though)


    Hi

    I have an app wich my team and I developped using Qt 5.6 and compiling it Qt 5.14 showed this weird bug :

    Untitled.png

    Text is messed up here and there

    The string is defined in the .ui file of the widget :
    886b1009-2375-4820-bfd0-6a26a245ccf4-image.png

    NB : the characters displayed seem to be of the formchar(expectedchar_asciicode - 1) :
    Show -> Rgnv

    Any idea of how i could possibly fix this ?

    Regards

    P 1 Reply Last reply 20 Mar 2020, 15:31
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 20 Mar 2020, 14:43 last edited by
      #2

      Please provide a minimal, compilable example and no screenshots from the code.

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

      U 1 Reply Last reply 20 Mar 2020, 14:50
      0
      • C Christian Ehrlicher
        20 Mar 2020, 14:43

        Please provide a minimal, compilable example and no screenshots from the code.

        U Offline
        U Offline
        Ulysse
        wrote on 20 Mar 2020, 14:50 last edited by Ulysse
        #3

        @Christian-Ehrlicher I can't : my project is huge and i don't know how to reproduce the bug
        I bet things work fine if i start somethting from the bottom up, it is a pretty basic functionnality

        I should be able to turn a Qt 5.6 project into a Qt 5.14 one.
        I am not aware of every line of code related to strings in the application itself because i did not write most of it.
        In fact i would like to know what i should look for, if you have any idea

        Regards

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 20 Mar 2020, 15:06 last edited by
          #4

          @Ulysse said in Wrong text display : Qt 5.14 only:

          I bet things work fine if i start somethting from the bottom up, it is a pretty basic functionnality

          At least you can try to prove it - if it does not work with a simple reproducer then copy your project and remove all stuff until it no longer happens. That's the way the find bugs and why you're a programmer.

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

          U 1 Reply Last reply 20 Mar 2020, 15:21
          0
          • C Christian Ehrlicher
            20 Mar 2020, 15:06

            @Ulysse said in Wrong text display : Qt 5.14 only:

            I bet things work fine if i start somethting from the bottom up, it is a pretty basic functionnality

            At least you can try to prove it - if it does not work with a simple reproducer then copy your project and remove all stuff until it no longer happens. That's the way the find bugs and why you're a programmer.

            U Offline
            U Offline
            Ulysse
            wrote on 20 Mar 2020, 15:21 last edited by Ulysse
            #5

            @Christian-Ehrlicher I am afraid you cannot do that when you have a 250'000 lines application.
            One has to narrow his search scope in order to solve bugs
            Thus my question : what should i look for ?
            And my that i mean particular functions calls, context, options.. anything

            Maybe you don't have any idea and that is fine, others will (even myself maybe?) and we will be able to locate the cause of the behavior
            But i won't be dismantling my whole application for obvious reasons

            Regards

            C 1 Reply Last reply 20 Mar 2020, 15:32
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 20 Mar 2020, 15:29 last edited by
              #6

              Hi,

              Where are you loading that text from ?
              Where are you setting that text ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • U Ulysse
                20 Mar 2020, 14:39

                TLDR :
                Font file needs to be loaded before the creation of objects that use them
                In my case :

                int main(int argc, char* argv[]){
                    // [...]
                    QApplication a(argc, argv);
                    QFontDatabase::addApplicationFont(":/police/roboto.ttf");
                    MainWindow w;
                    // [...]
                }
                

                Doing the other way around can cause the bug (could not reproduce the bug in a minimal example though)


                Hi

                I have an app wich my team and I developped using Qt 5.6 and compiling it Qt 5.14 showed this weird bug :

                Untitled.png

                Text is messed up here and there

                The string is defined in the .ui file of the widget :
                886b1009-2375-4820-bfd0-6a26a245ccf4-image.png

                NB : the characters displayed seem to be of the formchar(expectedchar_asciicode - 1) :
                Show -> Rgnv

                Any idea of how i could possibly fix this ?

                Regards

                P Offline
                P Offline
                Pl45m4
                wrote on 20 Mar 2020, 15:31 last edited by
                #7

                @Ulysse said in Wrong text display : Qt 5.14 only:

                the characters displayed seem to be of the formchar(expectedchar_asciicode - 1):
                Show -> Rgnv

                Do you convert / re-interpret or edit the string somewhere?

                Very unlikely that the issue comes from QString itself.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                0
                • U Ulysse
                  20 Mar 2020, 15:21

                  @Christian-Ehrlicher I am afraid you cannot do that when you have a 250'000 lines application.
                  One has to narrow his search scope in order to solve bugs
                  Thus my question : what should i look for ?
                  And my that i mean particular functions calls, context, options.. anything

                  Maybe you don't have any idea and that is fine, others will (even myself maybe?) and we will be able to locate the cause of the behavior
                  But i won't be dismantling my whole application for obvious reasons

                  Regards

                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 20 Mar 2020, 15:32 last edited by
                  #8

                  @Ulysse said in Wrong text display : Qt 5.14 only:

                  Thus my question : what should i look for ?

                  If you want to reproduce a bug, start, as already said, with a simple reproducer. If you then can't reproduce the issue - try to isolate the problem. Since it's a simple widget I'm pretty sure you don't need to touch every 250k lines...

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

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    Ulysse
                    wrote on 20 Mar 2020, 16:20 last edited by Ulysse
                    #9

                    We use the "roboto" TrueType font.
                    Commenting the QFontDatabase::addApplicationFont(":/police/roboto.ttf"); line in the main removes the problem
                    Has there been any changes between Qt 5.6 and Qt 5.14 that concerns TrueType fonts, or fonts in general ?

                    I can upload the font file if you need me to

                    Regards

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 20 Mar 2020, 16:26 last edited by
                      #10

                      So now that you've a point where to start - why not creating a simple reproducer??

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

                      U 1 Reply Last reply 20 Mar 2020, 16:57
                      0
                      • C Christian Ehrlicher
                        20 Mar 2020, 16:26

                        So now that you've a point where to start - why not creating a simple reproducer??

                        U Offline
                        U Offline
                        Ulysse
                        wrote on 20 Mar 2020, 16:57 last edited by Ulysse
                        #11

                        @Christian-Ehrlicher Because that is what i was doing of course
                        I was not able to reproduce it though
                        I verified and roboto is correctly used

                        #include <QMainWindow>
                        
                        QT_BEGIN_NAMESPACE
                        namespace Ui { class MainWindow; }
                        QT_END_NAMESPACE
                        
                        class MainWindow : public QMainWindow
                        {
                            Q_OBJECT
                        
                        public:
                            MainWindow(QWidget *parent = nullptr);
                            ~MainWindow();
                        
                        private:
                            Ui::MainWindow *ui;
                        };
                        
                        MainWindow::MainWindow(QWidget *parent)
                            : QMainWindow(parent)
                            , ui(new Ui::MainWindow)
                        {
                            ui->setupUi(this);
                        }
                        
                        MainWindow::~MainWindow()
                        {
                            delete ui;
                        }
                        
                        #include <QApplication>
                        #include <QFontDatabase>
                        
                        int main(int argc, char *argv[])
                        {
                            QApplication a(argc, argv);
                            MainWindow w;
                            QFontDatabase::addApplicationFont(":/police/roboto.ttf");
                            w.show();
                            return a.exec();
                        }
                        

                        mainwindow.ui :

                        <?xml version="1.0" encoding="UTF-8"?>
                        <ui version="4.0">
                         <class>MainWindow</class>
                         <widget class="QMainWindow" name="MainWindow">
                          <property name="geometry">
                           <rect>
                            <x>0</x>
                            <y>0</y>
                            <width>465</width>
                            <height>262</height>
                           </rect>
                          </property>
                          <property name="windowTitle">
                           <string>MainWindow</string>
                          </property>
                          <property name="styleSheet">
                           <string notr="true">QComboBox, QLabel, QAbstractSpinBox, QLineEdit, QTextBrowser, QRadioButton, QCheckBox
                        {
                        	font-family: &quot;Roboto Light&quot;;
                        	font-size: 40px;
                        	qproperty-alignment: AlignCenter;
                        	color: black;
                        	qproperty-contextMenuPolicy: NoContextMenu;
                        }</string>
                          </property>
                          <widget class="QWidget" name="centralwidget">
                           <layout class="QHBoxLayout" name="horizontalLayout">
                            <item>
                             <widget class="QLabel" name="label">
                              <property name="text">
                               <string>Hello World</string>
                              </property>
                             </widget>
                            </item>
                           </layout>
                          </widget>
                          <widget class="QMenuBar" name="menubar">
                           <property name="geometry">
                            <rect>
                             <x>0</x>
                             <y>0</y>
                             <width>465</width>
                             <height>25</height>
                            </rect>
                           </property>
                          </widget>
                          <widget class="QStatusBar" name="statusbar"/>
                         </widget>
                         <resources/>
                         <connections/>
                        </ui>
                        
                        1 Reply Last reply
                        0
                        • hskoglundH Offline
                          hskoglundH Offline
                          hskoglund
                          wrote on 20 Mar 2020, 20:09 last edited by
                          #12

                          Hi, just guessing but do you get the same error if you add the font from a disk file instead of an embedded resource, say like:

                          ...
                          MainWindow w;
                          QFontDatabase::addApplicationFont("roboto.ttf");
                          w.show();
                          ...
                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 20 Mar 2020, 20:32 last edited by
                            #13

                            Silly idea: what if you load the font before creating your MainWindow object ?

                            Instinctively, I would setup all external resources like this one before creating objects that will use them.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            U 1 Reply Last reply 21 Mar 2020, 09:55
                            4
                            • S SGaist
                              20 Mar 2020, 20:32

                              Silly idea: what if you load the font before creating your MainWindow object ?

                              Instinctively, I would setup all external resources like this one before creating objects that will use them.

                              U Offline
                              U Offline
                              Ulysse
                              wrote on 21 Mar 2020, 09:55 last edited by
                              #14

                              @SGaist And we have a winner ! That was the issue, thank you :)

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                es-w
                                wrote on 10 May 2020, 07:55 last edited by es-w 5 Oct 2020, 07:58
                                #15

                                Hi,
                                I have also had the same problem as OP but my GUI is QML and platform is Android It has a problem when I move my application from Qt 5.13.2 to Qt 5.14.2.
                                So now I just strict with Qt 5.13.2 (Even I would like to use a new feature for app bundle ) but I just curious why no one has the problem with display the wrong text after the move to Qt 5.14.2.

                                I try all method as OP and also load the font in QML and set the font to all display text but some text still displays wrong text i.e. under

                                Menu {
                                   title: "Languages"
                                  font: Fonts.fontDefault
                                }
                                

                                from above in GUI it's show "Languages " as below
                                de144dd8-413f-4731-a67f-7ecfd99d5a26-image.png

                                P 1 Reply Last reply 10 May 2020, 09:39
                                0
                                • E es-w
                                  10 May 2020, 07:55

                                  Hi,
                                  I have also had the same problem as OP but my GUI is QML and platform is Android It has a problem when I move my application from Qt 5.13.2 to Qt 5.14.2.
                                  So now I just strict with Qt 5.13.2 (Even I would like to use a new feature for app bundle ) but I just curious why no one has the problem with display the wrong text after the move to Qt 5.14.2.

                                  I try all method as OP and also load the font in QML and set the font to all display text but some text still displays wrong text i.e. under

                                  Menu {
                                     title: "Languages"
                                    font: Fonts.fontDefault
                                  }
                                  

                                  from above in GUI it's show "Languages " as below
                                  de144dd8-413f-4731-a67f-7ecfd99d5a26-image.png

                                  P Offline
                                  P Offline
                                  Pl45m4
                                  wrote on 10 May 2020, 09:39 last edited by
                                  #16

                                  @es-w

                                  Did you try what @SGaist suggested?


                                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                  ~E. W. Dijkstra

                                  E 1 Reply Last reply 10 May 2020, 10:19
                                  0
                                  • P Pl45m4
                                    10 May 2020, 09:39

                                    @es-w

                                    Did you try what @SGaist suggested?

                                    E Offline
                                    E Offline
                                    es-w
                                    wrote on 10 May 2020, 10:19 last edited by
                                    #17

                                    @Pl45m4 Already try it work on Windows but not for android

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      aludwig
                                      wrote on 2 Aug 2024, 11:02 last edited by
                                      #18

                                      @es-w Did you ever figure anything out on this? I'm having the same issue with QML in Qt 5.15.8 where some text is incorrect on the same screen as some correct text. I also explicitly set the font to Roboto prior to displaying any QML. The weird part is, is the same build works on one Red Hat VM, but does not work on a slightly different RH VM.

                                      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