Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QImage return null for format RGBA8888



  • I'm working on Qt application and I'm new to Qt, when I'm using Qimage to allocate the memory for RGBA8888 it returns null. However same call with RGB888 returns memory allocated. Code is given below:

    QImage *img_32 = nullptr;
    QImage *img_24 = nullptr;

    img_32 = new QImage((unsigned char*)data_ptr,width,hight,bytesperline,QImage::Format_RGBA8888); /*RGB32 color format */

    In debug window img_32 is "0"

    img_24 = new QImage((unsigned char*)data_ptr,width,hight,bytesperline,QImage::Format_RGB888); /*RGB24 color format */
    In debug window img_24 is non-zero value.

    For rendering image i'm using setPixmap(QPixmap).

    Queries:

    1. Is it right format for RGB32 ?
    2. Why RGB32 format gives NULL pointer.
    3. I want to render UYVY also, but Qt does not support UYVY. How to render UYVY in Qt ?

    Regards,
    Kulkarni.


  • Qt Champions 2019

    Your debug window is wrong (maybe due to optimizations of the compiler) and it has nothing to do with Qt since you're allocation a new object on the heap which will never return a nullptr (maybe in out-of-memory situations but then you would be unable to debug).
    And why do you allocate it in the heap instead just using an object?


Log in to reply