Results 1 to 4 of 4

Thread: QPrinter in qt4.1.3

  1. #1
    Join Date
    Aug 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QPrinter in qt4.1.3

    I try to write a simple program to print out a line from a printer.
    Following is my code:

    QPrinter printer(QPrinter::HighResolution);
    QPainter painter(&printer);
    painter.setPen(QColor(0,0,0));
    painter.drawLine(10,10,100,100);
    painter.end();

    But somehow, the program crash with error message: Access violation reading location.

    Can anyone tell me what's wrong with the code?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPrinter in qt4.1.3

    Have you set any page size for the printer?

  3. #3
    Join Date
    Aug 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPrinter in qt4.1.3

    Even i set all the print settings, the problem still there.

    Following is my settings:

    printer.setPageSize(QPrinter::Letter);
    printer.setColorMode(QPrinter::GrayScale);
    printer.setOrientation(QPrinter::Landscape);
    printer.setNumCopies(1);
    printer.setFullPage(true);


    The problem occured on line : painter.end();

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPrinter in qt4.1.3

    I think the painter might still be active when you call end(), although it should not crash.
    end() is called anyway in the destructor, so there is no need to actually call it manually.

Similar Threads

  1. QPrinter on QGraphicsScene Border Problem
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 15:49
  2. How can I put text on each page using QPrinter
    By davit in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2007, 12:23
  3. From QPrinter to QTextDocument
    By kemp in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2006, 15:44
  4. How to use QPrinter without QPrintDialog?
    By pascal456 in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2006, 19:57
  5. QPrinter on Solaris
    By ToddAtWSU in forum Qt Programming
    Replies: 4
    Last Post: 24th October 2006, 20:29

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.