Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perform deep copy over QImage

Tags:

c++

qt

How to perform a deep copy on a QImage?

What I have is like this:

texture_img = camWorker->getImage();

QImage CamWorker::getImage(){
    QMutexLocker locker(&mutex);
    return QImg;
}

and the QImg is from a stream Video. However I found that the texture_img = camWorker->getImage(); only performs a shallow copy over QImage, and when the QImg is changed in another thread it creates seg-fault. Will a deepcopy solve the problem?

like image 281
Nyaruko Avatar asked May 05 '15 08:05

Nyaruko


1 Answers

As Amartel has pointed out, QImage provides a copy method.

QImage image_copy = image.copy();

See here for more details.

like image 171
Nicholas Betsworth Avatar answered Sep 20 '22 00:09

Nicholas Betsworth