Results 1 to 6 of 6

Thread: QPainter::begin: A paint device can only be painted by one painter at a time.

  1. #1
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPainter::begin: A paint device can only be painted by one painter at a time.

    Hi

    i am using Qt4.4.3 over linux (fedora 8).
    I need to facilitate the auto-printing in my desktop application . So i dont want to show Print dialog to user. I such scenario to print the doc i did following:


    #ifndef QT_NO_PRINTER
    QPrinter printerObj(QPrinter::HighResolution);
    printerObj.setOrientation(QPrinter::Portrait);
    printerObj.setPageSize(QPrinter::A4);
    printerObj.setFullPage(true);
    printerObj.setNumCopies(1);

    QPainter painter(&printerObj);
    QTextDocument textDocument;
    textDocument.setHtml(msgStr);
    textDocument.print(&printerObj);
    #endif

    but by doing so its showing me following error message ( while running):

    QPainter::begin: A paint device can only be painted by one painter at a time.

    And sometimes its even crashing after that.

    Please suggest...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPainter::begin: A paint device can only be painted by one painter at a time.

    Qt Code:
    1. QPrinter printerObj(QPrinter::HighResolution);
    2. printerObj.setOrientation(QPrinter::Portrait);
    3. printerObj.setPageSize(QPrinter::A4);
    4. printerObj.setFullPage(true);
    5. printerObj.setNumCopies(1);
    6.  
    7. // QPainter painter(&printerObj); // << You don't need that! (causes the error.)
    8. QTextDocument textDocument;
    9. textDocument.setHtml(msgStr);
    10. textDocument.print(&printerObj);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter::begin: A paint device can only be painted by one painter at a time.

    if i try not to use QPainter then it crashes

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPainter::begin: A paint device can only be painted by one painter at a time.

    Quote Originally Posted by AviMittal View Post
    if i try not to use QPainter then it crashes
    What is your backtrace saying?

  5. #5
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter::begin: A paint device can only be painted by one painter at a time.

    this is backtrace:

    Printer::autoPrintFlag == true
    Program received signal SIGPIPE, Broken pipe.
    [Switching to Thread -1208396080 (LWP 26601)]
    0x00110402 in __kernel_vsyscall ()

    BACKTRACE:

    (gdb) bt
    #0 0x00110402 in __kernel_vsyscall ()
    #1 0x00c824ab in write () from /lib/libpthread.so.0
    #2 0x00ef3c09 in QFSFileEnginePrivate::writeFdFh (this=0xa0605d8,
    data=0xa072458 "%!PS-Adobe-1.0\n%%BoundingBox: 0 0 595 841 \n%%Creator: Qt 4.4.3\n%%CreationDate: Thu Oct 8 10:57:49 2009\n%%Orientation: Portrait\n%%Pages: (atend)\n%%DocumentFonts: (atend)\n%%EndComments\n%%BeginProlog\n% P"..., len=14479) at io/qfsfileengine.cpp:761
    #3 0x00efa7e2 in QFSFileEnginePrivate::nativeWrite (this=0xa0605d8,
    data=0xa072458 "%!PS-Adobe-1.0\n%%BoundingBox: 0 0 595 841 \n%%Creator: Qt 4.4.3\n%%CreationDate: Thu Oct 8 10:57:49 2009\n%%Orientation: Portrait\n%%Pages: (atend)\n%%DocumentFonts: (atend)\n%%EndComments\n%%BeginProlog\n% P"..., len=4294967264) at io/qfsfileengine_unix.cpp:317
    #4 0x00ef33a4 in QFSFileEngine::write (this=0xa06b090,
    data=0xa072458 "%!PS-Adobe-1.0\n%%BoundingBox: 0 0 595 841 \n%%Creator: Qt 4.4.3\n%%CreationDate: Thu Oct 8 10:57:49 2009\n%%Orientation: Portrait\n%%Pages: (atend)\n%%DocumentFonts: (atend)\n%%EndComments\n%%BeginProlog\n% P"..., len=14479) at io/qfsfileengine.cpp:735
    #5 0x00eb1575 in QFile::flush (this=0xa06a158) at io/qfile.cpp:1295
    #6 0x00eb18e7 in QFile::writeData (this=0xa06a158,
    data=0xa08caf8 "%%Page: 1 1 \n%%BeginPageSetup\nQI\n(F1) T1Setup\n%%EndPageSetup\nq\nQ\nQ q\nq\n0 0 0 scn\n/BSt 0 def\nQ\nQ q\n0 0 m\n9917 0 l\n9917 14033 l\n0 14033 l\n0 0 l\nh\nW* n\nq\n0 0 0 scn\n/BSt 0 def\n0.678431 0.847058 0.901960 s"..., len=10357) at io/qfile.cpp:1548
    #7 0x00eb927b in QIODevice::write (this=0xa06a158,
    data=0xa08caf8 "%%Page: 1 1 \n%%BeginPageSetup\nQI\n(F1) T1Setup\n%%EndPageSetup\nq\nQ\nQ q\nq\n0 0 0 scn\n/BSt 0 def\nQ\nQ q\n0 0 m\n9917 0 l\n9917 14033 l\n0 14033 l\n0 0 l\nh\nW* n\nq\n0 0 0 scn\n/BSt 0 def\n0.678431 0.847058 0.901960 s"..., maxSize=10357)
    at io/qiodevice.cpp:1262
    #8 0x00399756 in QPSPrintEnginePrivate::emitPages (this=0x9f94c60) at ../../include/QtCore/../../src/corelib/io/qiodevice.h:121
    #9 0x0039c22d in QPSPrintEnginePrivate::flushPage (this=0x9f94c60, last=true) at painting/qprintengine_ps.cpp:604
    #10 0x0039c729 in QPSPrintEngine::end (this=0xa046140) at painting/qprintengine_ps.cpp:715
    #11 0x0036a64d in QPainter::end (this=0xbfd1c5ac) at painting/qpainter.cpp:1782
    #12 0x0036a76a in ~QPainter (this=0xbfd1c5ac) at painting/qpainter.cpp:1380
    #13 0x00481496 in QTextDocument:rint (this=0xbfd20b78, printer=0xbfd20b6c) at text/qtextdocument.cpp:1645

  6. #6
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter::begin: A paint device can only be painted by one painter at a time.

    did anyone know about this???

Similar Threads

  1. problem in QPainter::begin
    By wagmare in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2009, 11:31
  2. Problem with Painter in Qt4.4.1
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 14:47
  3. QT 4.4.0 Upgrade QPainter Problem
    By ChrisReath in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2008, 16:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.