Warning generated on calling the capture slot form QCamera



  • Hello All,

    I am trying to run the below code :

     QByteArray cameraDevice;
        int cameraId = 1;
        QList<QByteArray> cameradev = QCamera::availableDevices();
        cameraDevice = cameradev[cameraId];
    
        QCamera *camera = new QCamera(cameraDevice);
    
        QString description = camera->deviceDescription(cameraDevice);
        qDebug()<<"Device Name"<< description;
    
        QCameraImageCapture *imageCapture = new QCameraImageCapture(camera);
        camera->setCaptureMode(QCamera::CaptureStillImage);
        camera->start();
    
        QImageEncoderSettings imageSettings;
        imageSettings.setCodec("image/jpeg");
        imageSettings.setResolution(1024,768);
        imageCapture->setEncodingSettings(imageSettings);
    
        imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
    
    
    //    Store image in buffer when captured
         QObject::connect(imageCapture, &QCameraImageCapture::imageCaptured, [=] (int id, QImage img) {
    
             img.save("samplerotated.jpeg","jpeg");
    
    
             QPoint center = img.rect().center();
             QMatrix matrix;
             matrix.translate(center.x(), center.y());
             matrix.rotate(-90);
             QImage dstImg = img.transformed(matrix);
    
             dstImg.save("New.jpeg","jpeg");
    
        });
    
    
        camera->searchAndLock();
        imageCapture->capture();
        camera->unlock();
        qDebug()<< camera->error();
    
    
    

    The code works fine but sometimes generates the following warning.
    QObject::moveToThread: Current thread (0x21d234e1db0) is not the object's thread (0x21d2ceeb370).
    Cannot move to target thread (0x21d234e1db0)

    How to resolve the following warning generated


  • Lifetime Qt Champion

    Hi,

    Are you calling moveToThread anywhere in your code ?


Log in to reply
 

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