I am trying to set the contents of a image file to QTextDocument so that i can send it to the printer but i am not able to get the contents of the file in the QTextDocument.

Some thing like following works
Qt Code:
  1. QTextDocument* document = new QTextDocument("Text");
To copy to clipboard, switch view to plain text mode 

But i dont want to pass the string i want the contents of a file. which is not working and the document is empty. Am I not using the addresource porperly. is there any other way to set the file contents to QTextDocument ?

Qt Code:
  1. const QUrl url = QUrl::fromLocalFile ( "/tmp/test.png" ) ;
  2. QTextDocument* document = new QTextDocument();
  3. document->addResource (QTextDocument::ImageResource, url, QVariant(QImage("/tmp/test.png")));
  4.  
  5. if (document->isEmpty())
  6. fprintf(stderr,"Document is empty");
To copy to clipboard, switch view to plain text mode