PDA

View Full Version : How to pass the contents of a text or html file to a text document



rannamal
2nd August 2010, 09:37
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



QTextDocument* document = new QTextDocument("Text");



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 ?




const QUrl url = QUrl::fromLocalFile ( "/tmp/test.png" ) ;
QTextDocument* document = new QTextDocument();
document->addResource (QTextDocument::ImageResource, url, QVariant(QImage("/tmp/test.png")));

if (document->isEmpty())
fprintf(stderr,"Document is empty");