Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-42011

Segmentation fault when trying to use QFontMetrics

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Not Evaluated Not Evaluated
    • None
    • 5.3.2
    • GUI: Font handling
    • None
    • Debian GNU/Linux unstable

      This minimal example results in a crash:

      #include <QtGui/QGuiApplication>
      #include <QtGui/QFont>
      #include <QtGui/QFontMetrics>
      
      int main(int argc, char **argv) {
          QGuiApplication(argc, argv);
          QFont font;
          QFontMetrics metrics(font);
      
          metrics.width('-');
          return 0;
      }
      

      The stack trace is:

      #0  initFontUnlocked () at kernel/qguiapplication.cpp:217
      #1  QGuiApplication::font () at kernel/qguiapplication.cpp:2699
      #2  0xb7b6740a in QFont::QFont (this=0xbffff33c) at text/qfont.cpp:688
      #3  0x0804882b in main (argc=1, argv=0xbffff414) at test.cpp:7
              font = {static staticMetaObject = {d = {superdata = 0x0, stringdata = 0xb7e4ff00 <qt_meta_stringdata_QFont>, 
                    data = 0xb7e4fe40 <qt_meta_data_QFont>, static_metacall = 0x0, relatedMetaObjects = 0x0, extradata = 0x0}}, d = {
                  d = 0x8048601 <_init+9>}, resolve_mask = 8}
              metrics = {d = {d = 0x8}}
      

      Line 217 of qguiapplication.cpp is:

      215	    if (!QGuiApplicationPrivate::app_font)
      216	        QGuiApplicationPrivate::app_font =
      217	            new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
      218	}
      

      Line 2699 is:

      2695	QFont QGuiApplication::font()
      2696	{
      2697	    Q_ASSERT_X(QGuiApplicationPrivate::self, "QGuiApplication::font()", "no QGuiApplication instance");
      2698	    QMutexLocker locker(&applicationFontMutex);
      2699	    initFontUnlocked();
      2700	    return *QGuiApplicationPrivate::app_font;
      2701	}
      

      Changing QGuiApplication to QApplication does not help.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            esabraha Eskil Abrahamsen Blomfeldt
            mandriver Dmitry Shachnev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes