I’m trying to use QPainter to draw items onto a QImage , but since I can’t predict the exact size of this QImage , I can’t use QImage::save() , it always tell me:
QPainter::begin: Paint device returned engine == 0, type: 3
But if I specify the image height and width when declaring this QImage , it works smoothly:
QImage output = QImage (500 , 500 , QImage::Format_ARGB32);
QImage,QPixmap, etc. require data to be allocated before drawing can begin. Using the default constructor ofQImagedoes not allocate any memory, soimage.isNull() == true. So when you callQPainter::begin()(probably indirectly by creating one with theQImageas the paint device) it can’t draw into any memory because it isn’t there.From the
QPainter::begin()docs:So you have to come up with a size before drawing. In your situation, the best thing to do would be to decide on a maximum size (or calculate one if feasible), and then once you do know the exact size – crop the image.