aligoglos
11th August 2017, 11:13
i have five class inherited from QThread that run all together and every class have own GUI resource like QLable* that get from main GUI thread. but when i start this five after some second exception occur. for resolve this i use global static Qmutex to lock/unlock part of code in run method.now i have button in main tread and want when press terminate all threads and unlock code but when Qmutex.unlock execute this exception rised :
Access violation writing location 0x000000000000000C
this is code of unlock :
static QMutex* mut = new QMutex();
inline void unlock()
{
if (mut!=nullptr)
{
mut->unlock();
}
}
and this is part of code in run method i want to lock:
mut->lock();
cv::Mat imgRGB; cv::cvtColor(out, imgRGB, CV_BGR2RGB);
QImage img(imgRGB.data, imgRGB.cols, imgRGB.rows, static_cast<int>(imgRGB.step),
QImage::Format_RGB888);
outPut->setPixmap(QPixmap::fromImage(img));
mut->unlock();
Access violation writing location 0x000000000000000C
this is code of unlock :
static QMutex* mut = new QMutex();
inline void unlock()
{
if (mut!=nullptr)
{
mut->unlock();
}
}
and this is part of code in run method i want to lock:
mut->lock();
cv::Mat imgRGB; cv::cvtColor(out, imgRGB, CV_BGR2RGB);
QImage img(imgRGB.data, imgRGB.cols, imgRGB.rows, static_cast<int>(imgRGB.step),
QImage::Format_RGB888);
outPut->setPixmap(QPixmap::fromImage(img));
mut->unlock();