Writing QImage into a buffer always returns error



  • Hi,
    I tried to write a QImage into buffer as follows,
    @
    bool MainWindow::somefunction(QImage &image)
    {
    QByteArray bytes;
    QBuffer buffer(&bytes);

    buffer.open(QIODevice::WriteOnly);
    
    if(image.save(&buffer, "JPG"))
    {
        qDebug() << "Error in writing to buffer";
        ui->imgLabel->setPixmap(QPixmap::fromImage(image)); // A test write, and it displays correctly in imgLabel
        buffer.close();
        return false;
    }
    buffer.close();
    return true;
    

    }
    @
    The image contained in QImage is verified using a write to imgLabel, but the above code always retuns error


  • Moderators

    [quote author="ras123" date="1361806714"]
    @
    if(image.save(&buffer, "JPG"))
    {
    qDebug() << "Error in writing to buffer";
    @
    [/quote]That displays an error message when you succeed :)



  • Thank you, I missed the not sign


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.