Sending a QImage between threads



  • Hi all, my aim is to use a thread to process QImages, and when the QImage is processed calling
    @this->update() @
    and painting the QImage using
    @painter.drawImage(framePos,putImage(frame));@

    is it better to use signals and slots to send the QImage between threads ?
    or am i best of doing this another method?

    (i need to process the QImages at precise interval's and i believe using a separate thread is the best way of doing this?)

    excuse my ignorance - i am new to Qt.

    Regards
    Tim.



  • If you want to do some processing on images in the background and keep the UI fluent you definitely want threads. If that is a QThread or a QRunnable or XYZ is a matter of taste and/or maybe depends on your program.
    IMHO using signals/slots is perfect for communication across thread boundaries.



  • Ok, thanks!
    i have a class 'player' which has this loop:
    @
    int delay = (1000/frameRate);
    QTime *ofSet;
    while(!stop){
    ofSet->start();
    if (!capture.read(frame))
    {
    stop = true;
    }
    emit processedImage(convertImage(frame));

        int fullOfset = delay - ofSet->elapsed();
        if(fullOfset > 0)
            this->msleep(fullOfset);
    }
    

    @

    because i use the msleep() function should i be running this class from within a thread?



  • As far as I remember it isn't even possible to sleep from within threads. Of course it's possible, but unwanted and needs some extra tweaks.
    IMHO the question is if you can read the capture device in another thread.
    Maybe you should have a look at QTimer to avoid the loop.
    And if you stay with your loop in the main thread you could think of converting the the other thread/slot function.





  • Yes, i understand that. the aim of my project though is to use OpenCV.
    Thanks alot for the help though, Hardcodes.


Log in to reply
 

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