Important: Please read the Qt Code of Conduct -

Load the liveview image from CanonSDK to QLabel

  • Hi and good day,

    I would like to show the liveview image from Canon SDK to QLabel. (I was using QLabel all this while to show the image and it seems fine)

    Or should I use different widget instead?

    Camera::requestDownloadEvfData(QImage& img)

    I was able to save in the folder using method, however, I am not able to set currentImage (QLabel) with the error QPixmap::scaled: Pixmap is a null pixmap.

    Below is the following code I use:

    void CameraView::LoadLiveViewImage(QImage& liveViewImage)
    currentImage->setPixmap(QPixmap::fromImage(liveViewImage).scaled(ui->baseLayout->cellRect(1, 0).width(), ui->baseLayout->cellRect(1, 0).height(), Qt::KeepAspectRatio));

    Probably I missed some steps instead?

    Thank you!

  • Lifetime Qt Champion

    QLabel is ok to use as fast way to display a pixmap. For more features, a custom widget with paintEvent is better.
    The error you get ( Pixmap is a null pixmap) sounds like is returning a NULL Pixmap

    is liveViewImage ok ?
    i would save img to file and look at it.

  • Hi,

    thanks for the reply, do you mean that I have to create custom widget in order for me to have paintEvent?

    It seems that occasionally, I will get null pixmap from requestDownloadEvfData, not sure though but i will add the checking on that.

    As you mentioned, QLabel is fine to use it, can I do looping on it? E.g.:

        QImage img;
        if ( cam != NULL && cam->hasOpenSession() && cam->isLiveViewing())
    } while (true);

    Yes, liveViewImage is okay, I have tried to use and it returns true. (Also from the directory, it indeed saves the image file).

  • Lifetime Qt Champion

    Sort of, if u create a custom widget, you can implement your own painting. Say if you needed some overlay or
    something like that.

    Looping in a GUI application is not a good idea as it will strangulate its event loop.
    It would be better using a QTimer and it its slot , just do the code without looping.
    (the timer will be the non blocking looping)

  • Hi,

    noted on that, I think for now I will try to implement the liveview feature using QLabel first.

    Thanks for the advices, I will check on QTimer, but as of now, it seems that I can't set the QLabel without saving into the local path first.

    currentImage->setPixmap(QPixmap::fromImage(testImage).scaled(ui->baseLayout->cellRect(1, 0).width(), ui->baseLayout->cellRect(1, 0).height(), Qt::KeepAspectRatio));

    Which means I can't feed liveViewImage into fromImage function, as it will not show any image at all.

    There's no compilation/runtime error though, do you think I have done in wrong way?

  • Lifetime Qt Champion

    The requestDownloadEvfData seems to be part of the SDK?
    I cant tell where/why it goes wrong. you need to inspect values. i think :)
    What does QImage::format() say?
    QImage img;
    qDebug() << img.format() << " null:" << img.QImage::isNull();
    Also for this. you are 100% sure the cellRect provides correct values?
    QPixmap::fromImage(testImage).scaled(ui->baseLayout->cellRect(1, 0).width(), ui->baseLayout->cellRect(1, 0).height(), Qt::KeepAspectRatio)

  • Hi,

    yes, requestDownloadEvfData is the wrapper function for the SDK, I will try to check on it why it's sometimes returning the odd value :D

    as for the QImage:format, it returns:
    4 null: false

    So I guess the wrong thing here goes when initializing the QPixmap, and yes, after debugging again, cellRect does not provide the value(and it's null instead).

    I am able to show the image by calling :

    without scaling it yet.

    Just my thought, as for the timer setup, since I will need to show liveview from the camera, would making it as little as possible be fine to the application? Just in terms of memory handling etc. :/

    for example; mLiveViewTimer.setInterval(10);

    Anyhow, thank you for the great advices to check things!

  • Lifetime Qt Champion

    It seems it sometimes returns invalid image so there must be something there.
    If you only capture 1 image and not store multiple (as video) its not so likely
    that memory will be an issue. Making it smaller will most likely allow you to capture faster and
    draw it.

  • @mrjj ,
    noted on that, I will check there too.

    As of right now, I have implemented the timer (10), and QLabel seems to be working now, just that there's gap in between the images that seems to look like a glitch (like sudden white screen).

  • Lifetime Qt Champion

    Hi, make sure you dont go too fast as the camera might have a min capture time.
    A white image sounds a bit odd, as it sounds like its being filled but no camera image is

  • @mrjj ,
    Hi, noted on that, I think for now the interval for the timer is sufficient. I will probably need to check again on the image as it's not reproducible sometimes.

    Anyhow, the main issue has been resolved. Thank you so much for the help!

Log in to reply