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 does not paint on QPrinter on release build

QPainter does not paint on QPrinter on release build

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 756 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.
  • E Offline
    E Offline
    Enym
    wrote on last edited by Enym
    #1

    Hello,

    On a debug build painting works fine. I tried building with both MSVC and MinGW.

    Here's a code snippet:

    void ReportPrinter::ShowPreviewDialog(QPrinter::OutputFormat format) {
        m_printer.setOutputFormat(format);
    
        QString selectedPageSize = m_pageSizeCombobox->currentText();
    
        if (selectedPageSize == "A4") {
            m_printer.setPageSize(QPrinter::A4);
        } else if (selectedPageSize == "A3") {
            m_printer.setPageSize(QPrinter::A3);
        } else if (selectedPageSize == "A2") {
            m_printer.setPageSize(QPrinter::A2);
        } else if (selectedPageSize == "A1") {
           m_printer.setPageSize(QPrinter::A1);
        } else if (selectedPageSize == "A0") {
            m_printer.setPageSize(QPrinter::A0);
        }
    
    
        QPrintPreviewDialog prevDlg(&m_printer, nullptr, Qt::Window);
        connect(&prevDlg, SIGNAL(paintRequested(QPrinter*)), this, SLOT(DrawOnPrinter(QPrinter*)));
        prevDlg.exec();
    }
    
    
    void ReportPrinter::DrawOnPrinter(QPrinter *printer) {
        QPainter painter;
        painter.begin(printer);
    
        qDebug() << "painterIsActive: " << painter.isActive(); // returns true on debug build and false on release build
        // painting code ....
    }
    

    Thanks in advance.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Qt version is also important :)

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Enym
        wrote on last edited by Enym
        #3

        Qt version: 5.7.

        jsulmJ 1 Reply Last reply
        0
        • E Enym

          Qt version: 5.7.

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Enym Does painter.begin(printer) return false? printer is not null in DrawOnPrinter (shouldn't be, but still worth checking)?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • E Offline
            E Offline
            Enym
            wrote on last edited by Enym
            #5

            Had a painter.begin() call in Q_ASSERT, which is obviously disabled in a release build. Stupid me :)

            Q_ASSERT(painter.begin(printer));
            
            jsulmJ 1 Reply Last reply
            3
            • E Enym

              Had a painter.begin() call in Q_ASSERT, which is obviously disabled in a release build. Stupid me :)

              Q_ASSERT(painter.begin(printer));
              
              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Enym Yes, don't put production code into asserts :-)

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              4

              • Login

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