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. QPainter setFont segmentation fault on app exit.
Forum Updated to NodeBB v4.3 + New Features

QPainter setFont segmentation fault on app exit.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 627 Views 1 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.
  • O Offline
    O Offline
    Oen44
    wrote on last edited by Oen44
    #1

    I'm using OpenGL to draw stuff, some of them have text. Everything works, nothing is glitching, no crashes, it's just great. The only thing that is bothering me is when I close the app, it's throwing segmentation fault. Debugger shows nothing but assembly so that wasn't helpful. I was able to narrow it down to this function:

    void OTUI::MainWindow::draw(QPainter& painter)
    {
        painter.save();
        painter.setPen(getColor());
        painter.setFont(getFont()); // this line is the reason
        //painter.setFont(QFont("Verdana", 11)); // same result
        painter.drawText(x(), y(), width(), 25, Qt::AlignCenter, getText());
        painter.restore();
    }
    

    19f897d0-e44d-46fc-a1c7-6f20a343cb34-image.png

    What to do? If you need more info, let me know.

    1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      It would really be nice to get a small example - this will maybe also help you to find out the reason by yourself.

      O Offline
      O Offline
      Oen44
      wrote on last edited by
      #5

      @Christian-Ehrlicher Alright, started from scratch, adding as little code from previous project as possible. Made it so it's creating OTUI::MainWindow on startup, no seg fault. Started adding more, creation from context menu etc. and still no crash. Then added last pieces, StartupWindow was one of them. It's a small window with list of recent projects that you can open or create new. It's a separated window that is opening second one (the one with OpenGL and all, CoreWindow) and hiding itself. What I was missing is deleting 2nd window when the app is closed, inside StartupWindow deconstructor.

      StartupWindow::~StartupWindow()
      {
          delete coreWindow; // this was missing
          delete ui;
      }
      
      1 Reply Last reply
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        From where do you call MainWindow::draw()? And please provide some more code - best would be 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

        O 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          From where do you call MainWindow::draw()? And please provide some more code - best would be a minimal, compilable example.

          O Offline
          O Offline
          Oen44
          wrote on last edited by
          #3

          @Christian-Ehrlicher From QOpenGLWidget::paintGL. You can clone project repository, nothing fancy needed to make it work straight away.
          https://github.com/Oen44/OTUIEditor

          Segmentation fault occurs when you create at least OTUI::MainWindow widget, even if it's then deleted. To do this, create new project, right-click on Widgets List panel on the left side and add Main Window, then simply close the app (you will be asked if you want to save the project, just press No), that's when segmentation fault happens.

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

            It would really be nice to get a small example - this will maybe also help you to find out the reason by yourself.

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

            O 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              It would really be nice to get a small example - this will maybe also help you to find out the reason by yourself.

              O Offline
              O Offline
              Oen44
              wrote on last edited by
              #5

              @Christian-Ehrlicher Alright, started from scratch, adding as little code from previous project as possible. Made it so it's creating OTUI::MainWindow on startup, no seg fault. Started adding more, creation from context menu etc. and still no crash. Then added last pieces, StartupWindow was one of them. It's a small window with list of recent projects that you can open or create new. It's a separated window that is opening second one (the one with OpenGL and all, CoreWindow) and hiding itself. What I was missing is deleting 2nd window when the app is closed, inside StartupWindow deconstructor.

              StartupWindow::~StartupWindow()
              {
                  delete coreWindow; // this was missing
                  delete ui;
              }
              
              1 Reply Last reply
              3
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6

                Nice - good example why a minimal, compilable example is useful and good to track down the bug by yourself in most cases :)

                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