QtPainter Error油漆设备返回引擎==0,类型3,油漆工未激活

QtPainter Error Paint device returned engine ==0, type 3 ,Painter not active

本文关键字:类型 油漆工 激活 引擎 Error 返回 QtPainter      更新时间:2023-10-16

我正在尝试绘制图像的某些点,但我不知道为什么它不起作用。我已经定义了一个QImage,我想修改一些点。

QImage *cou= new QImage(height,largeur,QImage::Format_Mono);
    cou->fill(1);
    QPainter *fig=new QPainter (cou);
    for (i=0;i<size_;i++)
    {
        fig-> drawPoint(floor(propa[i]),nbmax[i]);
    }

当我执行代码时,我获得

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

以及在以下行中:

QPainter::drawPoints: Painter not active
QPainter::begin: Paint device returned engine == 0, type: 3

该错误表示您尝试绘制的图像为空图像。使用cou上的isNull进行检查
图像为空的原因可能是构造图像时heightlargeur参数错误,或者

内存不足
QPaintEngine* eng = cou->painterEngine();
if(eng) {
//   create QPainter ...
}