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. QPrinter causes SIGPIPE error
Forum Update on Tuesday, May 27th 2025

QPrinter causes SIGPIPE error

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmlsigpipeqt 5.4.1qprinter
5 Posts 2 Posters 2.1k 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.
  • P Offline
    P Offline
    PhTe
    wrote on 13 Jan 2016, 07:39 last edited by
    #1

    I have a Qml application with Qt 5.4.1 and try to convert a HTML page to a PDF file.
    When i start my app and call the function to convert shortly after the startup it works all fine.
    But when i wait a few minutes after startup (My app does nothing else in this time, just showing the Qml ui) and then call the function, the QPrinter constructor causes a SIGPIPE - Broken Pipe error.

    Does anyone knows why? And how to prevent this?

    bool PdfExport::exportFile(const char *path) {
    
        QWebPage page;
        page.mainFrame()->setContent(exportString().c_str());
        printf("create printer\n");
        fflush(stdout);
        QPrinter *printer = new QPrinter(QPrinter::HighResolution); // Causes SIGPIPE error!!
    
        printf("set printer properties\n");
        fflush(stdout);
        printer->setPageMargins(5, 5, 5, 5, QPrinter::Millimeter);
        printer->setCreator(QString(this->creator.c_str()));
        printer->setDocName(QString(this->docName.c_str()));
        printer->setPageSize(QPrinter::A4);
        printer->setPrintRange(QPrinter::AllPages);
    
        printf("set output path\n");
        fflush(stdout);
        printer->setOutputFileName(path);
    
        printf("print\n");
        fflush(stdout);
        page.mainFrame()->print(printer);
    
        printf("delete printer\n");
        fflush(stdout);
    
        delete printer;
    
        printf("finish\n");
        fflush(stdout);
    
        return true;
    }
    

    I have already added

    void handler(int s) {
        printf("Caught SIGPIPE %d\n", s);
        fflush(stdout);
    }
    
    int main(int argc, char *argv[]) {
    
        signal(SIGPIPE, handler);
    
        struct sigaction sa;
        sa.sa_handler = handler;
        sa.sa_flags = 0;
        if (sigaction(SIGPIPE, &sa, 0) == -1) {
          printf("Could not set SIGPIPE handler\n");
        }
        ....
    

    in my main function. but the handler is never called...

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 13 Jan 2016, 08:10 last edited by
      #2

      Why do you create QPrinter on the heap?

      One note: you are using printf() C function for debugging. With Qt you can use:

      qDebug() << "SOME TEXT";
      

      Or at least std::cout, at the end you are writing C++ code :-)

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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PhTe
        wrote on 13 Jan 2016, 08:39 last edited by
        #3

        I know i could use qDebug oder cout.

        It should not make any difference if i create QPrinter on the heap or as a member variable of my class, does it?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 13 Jan 2016, 09:07 last edited by
          #4

          It should not make a difference.
          You could debug into QPrinter constructor to see where exactly the problem is.

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

          1 Reply Last reply
          0
          • P Offline
            P Offline
            PhTe
            wrote on 13 Jan 2016, 13:08 last edited by
            #5

            I will try to debug in QPrinter, but therefore i have to compile QT in debug mode. It will take a while..

            1 Reply Last reply
            0

            1/5

            13 Jan 2016, 07:39

            • Login

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