Printing with qt5
-
Hi
QML cannot directly print as far as i know. You have to sent it to c++ side and do it there.
https://forum.qt.io/topic/57861/solved-how-to-take-a-print-in-qml/14 -
Hello, thank you for link. I used this example as template but i got my application not to run. I do not know how to handle this error message.
@cupressus Hi, for this error message, you just need to include <QQmlContext> (I don't know qml though)
-
@cupressus
Ok that dont look right :)Try save image to a file and see how it looks to know if its something printer or
the image really is that bad.void pr::print(QVariant data)
{
QImage img = qvariant_cast<QImage>(data);
img.save(xxxx) <<<<<<<<<<<<<<<<<<<<< try save it
QPrinter printer;
QPrintDialog *dlg = new QPrintDialog(&printer,0);
if(dlg->exec() == QDialog::Accepted) {
QPainter painter(&printer);
painter.drawImage(QPoint(0,0),img);
painter.end();
}
}