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. Crash with QFontMetrics::elidedText

Crash with QFontMetrics::elidedText

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 791 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.
  • A Offline
    A Offline
    ajaxcrypto
    wrote on last edited by
    #1

    Calling QFontMetrics::elidedText leads to a crash (call on GUI thread), which crash coming from QFontPrivateData.
    Here is the callstack:

     Qt5Guid.dll!QAtomicOpsBySize<4>::ref<int>(int & _q_value) Line 308	C++
     Qt5Guid.dll!QBasicAtomicInteger<int>::ref() Line 113	C++ 
     Qt5Guid.dll!QExplicitlySharedDataPointer<QFontPrivate>::QExplicitlySharedDataPointer<QFontPrivate>(QFontPrivate * adata) Line 264	C++
     Qt5Guid.dll!QFont::QFont(QFontPrivate * data) Line 565	C++
     Qt5Guid.dll!QFontMetrics::elidedText(const QString & text, Qt::TextElideMode mode, int width, int flags) Line 905	C++
    
    

    This is on Windows 10, Qt 5.9.1 with MSVC 2015 (No optimization flags enabled)

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please provide a minimal, compilable example.

      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
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Please provide a minimal compilable example that triggers the crash.

        You should also consider updating your version of Qt. Qt 5.9.1 is quite old.

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

        A 1 Reply Last reply
        0
        • A Offline
          A Offline
          ajaxcrypto
          wrote on last edited by ajaxcrypto
          #4
          static const QFont font{ "Consolas", 9, 100 };
          
          // This function is frequently called, font and width remain constant
          std::pair<int, const QFontMetrics&> GetInfo() 
          {
              static QFontMetrics metrics{font};
              static int width = metrics.averageCharWidth() * MAX_CHARS_REQUIRED; // some constant
              return std::make_pair(width, metrics);
          }
          
          int main(int argc, char** argv)
          {
              QApplication app(argc, argv);
              auto pair = GetInfo();
              auto txt = pair.second.elidedText("some long text", Qt::ElideRight, pair.first); // crash here
              std::cout << text.toStdString();
              return app.exec();
          }
          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Please provide a minimal compilable example that triggers the crash.

            You should also consider updating your version of Qt. Qt 5.9.1 is quite old.

            A Offline
            A Offline
            ajaxcrypto
            wrote on last edited by
            #5

            @SGaist Unfortunately, I can't update the Qt version. We might eventually mode to Qt6 (at a later date)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              That code has an issue, it's missing a QApplication object. It's mandatory to setup Qt's internals that needs to access graphic system related data/information.

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

              A 1 Reply Last reply
              0
              • SGaistS SGaist

                That code has an issue, it's missing a QApplication object. It's mandatory to setup Qt's internals that needs to access graphic system related data/information.

                A Offline
                A Offline
                ajaxcrypto
                wrote on last edited by
                #7

                @SGaist I ommitted certain pieces. QApplication as well as QWindow exists in the real one.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Here is the issue: with missing bits and pieces, your minimal application does not reflect your situation so it is likely hiding the real issue.

                  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
                  0
                  • A Offline
                    A Offline
                    ajaxcrypto
                    wrote on last edited by
                    #9

                    I can't really copy paste the entire application code here. But what are the possible scenarios in which I can face error from QFontPrivate ? Or it too vague to guess?

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      You return a dangling QFontMetrics reference.

                      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
                      • Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by Christian Ehrlicher
                        #11

                        To be more precise: you're failing to due std::make_pair: "The deduced types V1 and V2 are std::decay<T1>::type and std::decay<T2>::type"

                        So either use return std::pair<int, const QFontMetrics &>(width, metrics); or since you prefer (although very very inconsistent) brace initialization return {width, metrics};

                        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
                        2

                        • Login

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