QPainter::begin(): returned false error with Qt Creator 5.7 on iMX6

QPrinter printer;
             QPainter painter;
             if (! painter.begin(&printer)) { // failed to open file
                   qWarning("failed to open file, is it writable?");
                   return 0;
             painter.drawText(10, 10, "Testing the automaization of this printer");
             QString str="Pdf is ready to print";


Whenever i run this snippet on the PC it works fine like it should but whenever we deploy in the IMX6 board it gives an error QPainter::begin(): returned false error

Assuming Linux, please follow the How to set up Qt Creator to cross compile for embedded Linux article to setup Qt development environment on host and have an image on the module with Qt libraries deployed. The default demo images do not have Qt libraries.