carobnodrvo
1st March 2016, 10:34
Recently I've been testing my Qt 5.5 C++ (Win7) program on one older laptop and found a weird bug, namely I'm displaying camera image and on some action (when letter P is pressed on keyboard) save that image in Pictures folder. Everything works fine (on P click image is saved) until I start new thread (for doing some background process). After the new thread is started, on "take a picture" event nothing happens (image is not visible in Pictures folder; onImageError[/ is not called) and after I close the application all images that are being captured are saved.
I'm not sure if I made myself clear so here is one more time steps I perform:
Open app -> take a photo -> photo is saved -> start new thread -> take couple of pictures (they are not saved) -> close app -> app closed (ALL pictures are saved)
The important part I have to mention is that all object I use (QCamera, QCameraImageCapture and thread that I start) are pointers.
And I am not 100% sure that starting this thread cause the issue but every time I start the thread, images are not saved.
Here are source that I am using:
Capturing camera image:
void MyClass::onCameraSeleced(QCameraInfo camera_info) {
camera_ = new QCamera(camera_info);
pture(camera_);
camera_image_capture_->setCaptureDestination(QCameraImageCapture::Capture ToFile);
camera_image_capture_ = new QCameraImageCa
// connect to capture signals
connect(camera_image_capture_, SIGNAL(imageCaptured(int, const QImage&)),
this, SLOT(onImageCaptured(int, const QImage&)));
connect(camera_image_capture_, SIGNAL(imageSaved(int, const QString&)),
this, SLOT(onImageSaved(int, const QString&)));
connect(camera_image_capture_, SIGNAL(error(int,QCameraImageCapture::Error,QStrin g)), this,
SLOT(onImageError(int,QCameraImageCapture::Error,Q String)));
camera_->setCaptureMode(QCamera::CaptureStillImage);
camera_->setViewfinder(ui->cameraWidget);
camera_->start();
}
void MyClass::takeScreenShot(){
camera_->searchAndLock();
camera_image_capture_->capture(name);
camera_->unlock();
}
MyClass::~MyClass()
{
if(camera_ != NULL)
{
camera_->unload();
delete camera_;
}
}
Starting new thread that cause this issue:
my_thread_ = new MyThread();
QThreadPool::globalInstance()->start(my_thread_);
MyThread:
void MyThread::run()
{
while(run_)
{
.
.
.
QThread::msleep(static_speed_yaw_data_->getTimeInterval());
}
}
I'm not sure if I made myself clear so here is one more time steps I perform:
Open app -> take a photo -> photo is saved -> start new thread -> take couple of pictures (they are not saved) -> close app -> app closed (ALL pictures are saved)
The important part I have to mention is that all object I use (QCamera, QCameraImageCapture and thread that I start) are pointers.
And I am not 100% sure that starting this thread cause the issue but every time I start the thread, images are not saved.
Here are source that I am using:
Capturing camera image:
void MyClass::onCameraSeleced(QCameraInfo camera_info) {
camera_ = new QCamera(camera_info);
pture(camera_);
camera_image_capture_->setCaptureDestination(QCameraImageCapture::Capture ToFile);
camera_image_capture_ = new QCameraImageCa
// connect to capture signals
connect(camera_image_capture_, SIGNAL(imageCaptured(int, const QImage&)),
this, SLOT(onImageCaptured(int, const QImage&)));
connect(camera_image_capture_, SIGNAL(imageSaved(int, const QString&)),
this, SLOT(onImageSaved(int, const QString&)));
connect(camera_image_capture_, SIGNAL(error(int,QCameraImageCapture::Error,QStrin g)), this,
SLOT(onImageError(int,QCameraImageCapture::Error,Q String)));
camera_->setCaptureMode(QCamera::CaptureStillImage);
camera_->setViewfinder(ui->cameraWidget);
camera_->start();
}
void MyClass::takeScreenShot(){
camera_->searchAndLock();
camera_image_capture_->capture(name);
camera_->unlock();
}
MyClass::~MyClass()
{
if(camera_ != NULL)
{
camera_->unload();
delete camera_;
}
}
Starting new thread that cause this issue:
my_thread_ = new MyThread();
QThreadPool::globalInstance()->start(my_thread_);
MyThread:
void MyThread::run()
{
while(run_)
{
.
.
.
QThread::msleep(static_speed_yaw_data_->getTimeInterval());
}
}