Results 1 to 3 of 3

Thread: QPrinter setOutputFileName

  1. #1
    Join Date
    Sep 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    4
    Thanked 5 Times in 1 Post

    Default QPrinter setOutputFileName

    Hi,

    I'm trying to save a QDocument as pdf file on a specific location.
    Qt Code:
    1. QPrinter toPdf;
    2. toPdf.setOutputFormat(QPrinter::PdfFormat);
    3. toPdf.setOutputFileName("test.pdf");
    To copy to clipboard, switch view to plain text mode 
    works, but when I'm trying to write a pdf file to a certain directory, i.e. home directory:
    Qt Code:
    1. QPrinter toPdf;
    2. toPdf.setOutputFormat(QPrinter::PdfFormat);
    3. toPdf.setOutputFileName("~/test.pdf");
    To copy to clipboard, switch view to plain text mode 
    it doesn't work and I get this message:
    Qt Code:
    1. QPainter::begin(): Returned false
    To copy to clipboard, switch view to plain text mode 

    Does anyone know how to solve this or if there is another way of doing this?
    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QPrinter setOutputFileName

    Isn't ~ interpreted by the shell? You don't have a shell here thus you should provide a valid path, like /home/myusername/test.pdf or QString("%1/test.pdf").arg(genenv("HOME")).

  3. The following user says thank you to wysota for this useful post:

    maartenS (17th November 2008)

  4. #3
    Join Date
    Sep 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    4
    Thanked 5 Times in 1 Post

    Default Re: QPrinter setOutputFileName

    Thanks! That was the problem.

Similar Threads

  1. QPrinter problem
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 20th February 2008, 21:20
  2. QPrinter on QGraphicsScene Border Problem
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 16:49
  3. QPrinter problems
    By Teuniz in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2007, 09:51
  4. How to use QPrinter without QPrintDialog?
    By pascal456 in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2006, 20:57
  5. QPrinter on Solaris
    By ToddAtWSU in forum Qt Programming
    Replies: 4
    Last Post: 24th October 2006, 21: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
  •  
Qt is a trademark of The Qt Company.