PDA

View Full Version : QPainter error saving an image from a QGraphicsScene



cydside
27th January 2010, 22:21
Hi to all,
I'm now compiling, without errors, a project using the latest Qt release (4.6) and created with the previous Qt 4.5.4 release (Windows).
I'm coding my function using the example reported in "The Graphics View Framework" included in the Qt Help but now it isn't working. The message :


QPainter::begin: Paint device returned engine == 0, type: 2

is appearing in my "Application Out"!!!

Here is the code:



void frmStats::creaFileHtml()
{
QString intestazioneFile =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN "
"http://www.w3.org/TR/html4/strict.dtd\">\n"
"<html>\n"
"<head>\n"
"<meta content=\"text/html;"
"charset=UTF-8\" http-equiv=\"content-type\">\n"
"<title></title>\n"
"</head>\n"
"<body>\n";

QString chiusuraFile =
"</body>\n"
"</html>\n";

html.clear();

html += intestazioneFile;

QPixmap pixmap(endX, endY);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
scene->render(&painter); // scene = new QGraphicsScene(QRect(0, 0, endX, endY), this);
painter.end();
pixmap.save(QDir::currentPath() + "/statistiche.png");

html += "<img src=\"" + QDir::currentPath() +
"/statistiche.png\" ALIGN=\"center\">\n<br>\n";

html += chiusuraFile;
// qDebug() << "HTML: " << html;
}



What happens?

Thanks!

cydside
28th January 2010, 07:19
Sorry guys, it has been a my error!
Solved.

Wazman
28th January 2010, 20:00
Could you explain how you solved your problem?

cydside
29th January 2010, 04:53
Ok, but I'm warning you, it's quite strange. So I've commented the problem core lines:



QPixmap pixmap(endX, endY);
QPainter painter(&pixmap);
// painter.setRenderHint(QPainter::Antialiasing);
// scene->render(&painter);
// painter.end();
// pixmap.save(QDir::currentPath() + "/statistiche.png");


leaving only the QPainter declaration. That to find which instruction was the problem. And Taaa Daaa line by line I arrived at the end without having the error anymore!!!
I don't know if it depends by the compiler (just a flicker) or my PC but now is working, that's my honest work, believe or not.