Search code examples
opencvqt4.7qimageiplimage

"QImage with no type" compile error message


Hello Can anyone help me figure out how to solve this bug message? I am trying to rewrite a Qt3 working code into Qt4 for converting IplImage to QImage and found the "right conversion types" however my code as below results in " ISO C++ forbids declaration of 'QImage' with no type"

....
QImage *qqImage;
if (this->data->nChannels == 1)
{

    QVector<QRgb> myColorTable;
    for (int i = 0; i < 256; i++)
        myColorTable.push_back(qRgb(i, i, i)); //colorTable[i]);


    qqImage = new QImage(qImageBuffer, width, height, QImage::Format_Indexed8);
}
else
{

    qqImage = new QImage(qImageBuffer, width, height, QImage::Format_RGB32);

}

return qqImage;

Solution

  • The code piece below works on my Qt4 app, give it a try.

        // img1 and img2 are Mat objects, img1 is grayscale,
        // img2 is three channel RGB image
    
        QImage qimg1,qimg2;
    
        if (this->data->nChannels == 1){
    
        qimg1=QImage(img1.data,img1.cols,img1.rows,QImage::Format_Indexed8);
    
        }
    
        else {
    
        qimg2=QImage(img2.data,img2.cols,img2.rows,QImage::Format_RGB888);
    
        }