Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A camera problem.
Forum Updated to NodeBB v4.3 + New Features

A camera problem.

Scheduled Pinned Locked Moved Unsolved General and Desktop
91 Posts 7 Posters 18.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #18

    The buffer just means it's in memory. You'll get a frame to process and then it's up to you to save it.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    J 1 Reply Last reply
    0
    • SGaistS SGaist

      The buffer just means it's in memory. You'll get a frame to process and then it's up to you to save it.

      J Offline
      J Offline
      jenya7
      wrote on last edited by
      #19

      @SGaist said in A camera problem.:

      The buffer just means it's in memory. You'll get a frame to process and then it's up to you to save it.

      After

      g_camera.SetCaptureMode(QCamera::CaptureMode::CaptureStillImage);
      g_camera.takeImage();
      

      Nothing happens. I didn't get to

      void Camera::processCapturedImage(int requestId, const QImage& img)
      

      or

      void Camera::imageSaved(int id, const QString &fileName)
      

      How do I know where is the image (if it was taken at all)?

      jsulmJ 1 Reply Last reply
      0
      • J jenya7

        @SGaist said in A camera problem.:

        The buffer just means it's in memory. You'll get a frame to process and then it's up to you to save it.

        After

        g_camera.SetCaptureMode(QCamera::CaptureMode::CaptureStillImage);
        g_camera.takeImage();
        

        Nothing happens. I didn't get to

        void Camera::processCapturedImage(int requestId, const QImage& img)
        

        or

        void Camera::imageSaved(int id, const QString &fileName)
        

        How do I know where is the image (if it was taken at all)?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #20

        @jenya7 Did you connect a slot to https://doc.qt.io/qt-5/qcamera.html#errorOccurred to see whether you get any errors? Same for https://doc.qt.io/qt-5/qcameraimagecapture.html#error-1
        You can get the cptured image using this signal: https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        J 1 Reply Last reply
        0
        • jsulmJ jsulm

          @jenya7 Did you connect a slot to https://doc.qt.io/qt-5/qcamera.html#errorOccurred to see whether you get any errors? Same for https://doc.qt.io/qt-5/qcameraimagecapture.html#error-1
          You can get the cptured image using this signal: https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable

          J Offline
          J Offline
          jenya7
          wrote on last edited by jenya7
          #21

          @jsulm said in A camera problem.:

          @jenya7 Did you connect a slot to https://doc.qt.io/qt-5/qcamera.html#errorOccurred to see whether you get any errors? Same for https://doc.qt.io/qt-5/qcameraimagecapture.html#error-1
          You can get the cptured image using this signal: https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable

          this is what I have

          connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &Camera::readyForCapture);
          connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &Camera::processCapturedImage);
          connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &Camera::imageSaved);
          connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error),
                      this, &Camera::displayCaptureError);
          
          jsulmJ 1 Reply Last reply
          0
          • J jenya7

            @jsulm said in A camera problem.:

            @jenya7 Did you connect a slot to https://doc.qt.io/qt-5/qcamera.html#errorOccurred to see whether you get any errors? Same for https://doc.qt.io/qt-5/qcameraimagecapture.html#error-1
            You can get the cptured image using this signal: https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable

            this is what I have

            connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &Camera::readyForCapture);
            connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &Camera::processCapturedImage);
            connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &Camera::imageSaved);
            connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error),
                        this, &Camera::displayCaptureError);
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #22

            @jenya7 So, what about trying https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable ?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            J 1 Reply Last reply
            0
            • jsulmJ jsulm

              @jenya7 So, what about trying https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable ?

              J Offline
              J Offline
              jenya7
              wrote on last edited by jenya7
              #23

              @jsulm said in A camera problem.:

              @jenya7 So, what about trying https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable ?

              I did in Camera::setCamera

              connect(m_imageCapture.data(), &QCameraImageCapture::imageAvailable, this, &Camera::ImageAvailable);
              

              and then

              void Camera::ImageAvailable(int id, const QVideoFrame &frame)
              {
                   qDebug() <<  id;
                   //qDebug() << frame->???;
              }
              

              I also added

              void Camera::displayCameraError()
              {
                  //QMessageBox::warning(this, tr("Camera Error"), m_camera->errorString());
                  qDebug() << "Camera Error: " + m_camera->errorString() + "\n";
              }
              
              void Camera::displayCaptureError(int id, const QCameraImageCapture::Error error, const QString &errorString)
              {
                  Q_UNUSED(id);
                  Q_UNUSED(error);
                  qDebug() << "Image Capture Error: " + errorString;
                  m_isCapturingImage = false;
              }
              

              and when I do

              g_camera.SetCaptureMode(QCamera::CaptureMode::CaptureStillImage);
              g_camera.takeImage();
              

              I get

              "Image Capture Error: Camera not ready"
              

              How can I know a reason why the camera isn't ready?

              jsulmJ 1 Reply Last reply
              0
              • J jenya7

                @jsulm said in A camera problem.:

                @jenya7 So, what about trying https://doc.qt.io/qt-5/qcameraimagecapture.html#imageAvailable ?

                I did in Camera::setCamera

                connect(m_imageCapture.data(), &QCameraImageCapture::imageAvailable, this, &Camera::ImageAvailable);
                

                and then

                void Camera::ImageAvailable(int id, const QVideoFrame &frame)
                {
                     qDebug() <<  id;
                     //qDebug() << frame->???;
                }
                

                I also added

                void Camera::displayCameraError()
                {
                    //QMessageBox::warning(this, tr("Camera Error"), m_camera->errorString());
                    qDebug() << "Camera Error: " + m_camera->errorString() + "\n";
                }
                
                void Camera::displayCaptureError(int id, const QCameraImageCapture::Error error, const QString &errorString)
                {
                    Q_UNUSED(id);
                    Q_UNUSED(error);
                    qDebug() << "Image Capture Error: " + errorString;
                    m_isCapturingImage = false;
                }
                

                and when I do

                g_camera.SetCaptureMode(QCamera::CaptureMode::CaptureStillImage);
                g_camera.takeImage();
                

                I get

                "Image Capture Error: Camera not ready"
                

                How can I know a reason why the camera isn't ready?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #24

                @jenya7 Did you call

                camera->setCaptureMode(QCamera::CaptureStillImage);
                camera->start();
                //on half pressed shutter button
                camera->searchAndLock();
                
                //on shutter button pressed
                imageCapture->capture();
                

                like shown in https://doc.qt.io/qt-5/qcameraimagecapture.html ?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @jenya7 Did you call

                  camera->setCaptureMode(QCamera::CaptureStillImage);
                  camera->start();
                  //on half pressed shutter button
                  camera->searchAndLock();
                  
                  //on shutter button pressed
                  imageCapture->capture();
                  

                  like shown in https://doc.qt.io/qt-5/qcameraimagecapture.html ?

                  J Offline
                  J Offline
                  jenya7
                  wrote on last edited by jenya7
                  #25

                  @jsulm said in A camera problem.:

                  @jenya7 Did you call

                  camera->setCaptureMode(QCamera::CaptureStillImage);
                  camera->start();
                  //on half pressed shutter button
                  camera->searchAndLock();
                  
                  //on shutter button pressed
                  imageCapture->capture();
                  

                  like shown in https://doc.qt.io/qt-5/qcameraimagecapture.html ?

                  I thought

                  void Camera::takeImage()
                  {
                      m_isCapturingImage = true;
                      m_imageCapture->capture();
                  }
                  

                  handles all this, kinda higher layer that wraps all together.
                  and what is
                  //on half pressed shutter button
                  //on shutter button pressed
                  I don't have any buttons. my app is not widget controlled. all commands issued from a command line.
                  I took a widget camera example (from Examples) and removed all UI related staff.

                  jsulmJ 1 Reply Last reply
                  0
                  • J jenya7

                    @jsulm said in A camera problem.:

                    @jenya7 Did you call

                    camera->setCaptureMode(QCamera::CaptureStillImage);
                    camera->start();
                    //on half pressed shutter button
                    camera->searchAndLock();
                    
                    //on shutter button pressed
                    imageCapture->capture();
                    

                    like shown in https://doc.qt.io/qt-5/qcameraimagecapture.html ?

                    I thought

                    void Camera::takeImage()
                    {
                        m_isCapturingImage = true;
                        m_imageCapture->capture();
                    }
                    

                    handles all this, kinda higher layer that wraps all together.
                    and what is
                    //on half pressed shutter button
                    //on shutter button pressed
                    I don't have any buttons. my app is not widget controlled. all commands issued from a command line.
                    I took a widget camera example (from Examples) and removed all UI related staff.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #26

                    @jenya7 said in A camera problem.:

                    I don't have any buttons.

                    These comments simply tell you that these methods simulate these buttons.
                    So, yes you have to set the capture mode, start the camera, call searchAndLock and then capture.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    J 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @jenya7 said in A camera problem.:

                      I don't have any buttons.

                      These comments simply tell you that these methods simulate these buttons.
                      So, yes you have to set the capture mode, start the camera, call searchAndLock and then capture.

                      J Offline
                      J Offline
                      jenya7
                      wrote on last edited by
                      #27

                      @jsulm said in A camera problem.:

                      @jenya7 said in A camera problem.:

                      I don't have any buttons.

                      These comments simply tell you that these methods simulate these buttons.
                      So, yes you have to set the capture mode, start the camera, call searchAndLock and then capture.

                      I changed to

                      void Camera::takeImage()
                      {
                          m_camera->start();
                          m_camera->searchAndLock();
                      
                          m_isCapturingImage = true;
                          m_imageCapture->capture();
                      }
                      

                      I still have
                      "Image Capture Error: Camera not ready"
                      Do I need to set a Viewfinder?
                      I commented out those lines

                      //QCameraViewfinder *v_finder = new QCameraViewfinder();
                      //v_finder->setFixedSize(240, 320);
                      //v_finder->show();
                      //v_finder->setAttribute(Qt::WA_NoSystemBackground);
                      //m_camera->setViewfinder(v_finder);
                      

                      cause I get an exception on
                      QCameraViewfinder *v_finder = new QCameraViewfinder();

                      jsulmJ 1 Reply Last reply
                      0
                      • J jenya7

                        @jsulm said in A camera problem.:

                        @jenya7 said in A camera problem.:

                        I don't have any buttons.

                        These comments simply tell you that these methods simulate these buttons.
                        So, yes you have to set the capture mode, start the camera, call searchAndLock and then capture.

                        I changed to

                        void Camera::takeImage()
                        {
                            m_camera->start();
                            m_camera->searchAndLock();
                        
                            m_isCapturingImage = true;
                            m_imageCapture->capture();
                        }
                        

                        I still have
                        "Image Capture Error: Camera not ready"
                        Do I need to set a Viewfinder?
                        I commented out those lines

                        //QCameraViewfinder *v_finder = new QCameraViewfinder();
                        //v_finder->setFixedSize(240, 320);
                        //v_finder->show();
                        //v_finder->setAttribute(Qt::WA_NoSystemBackground);
                        //m_camera->setViewfinder(v_finder);
                        

                        cause I get an exception on
                        QCameraViewfinder *v_finder = new QCameraViewfinder();

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #28

                        @jenya7 For capturing images view finder should not be needed.
                        But you could try to enable it to see whether your camera works at all in Qt.
                        What exception do you get?

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        J 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @jenya7 For capturing images view finder should not be needed.
                          But you could try to enable it to see whether your camera works at all in Qt.
                          What exception do you get?

                          J Offline
                          J Offline
                          jenya7
                          wrote on last edited by
                          #29

                          @jsulm said in A camera problem.:

                          @jenya7 For capturing images view finder should not be needed.
                          But you could try to enable it to see whether your camera works at all in Qt.
                          What exception do you get?

                          I get
                          The inferior stopped because it received a signal from the operating system.
                          Signal name: SIGABRT
                          Signal meaning: Aborted

                          jsulmJ 1 Reply Last reply
                          0
                          • J jenya7

                            @jsulm said in A camera problem.:

                            @jenya7 For capturing images view finder should not be needed.
                            But you could try to enable it to see whether your camera works at all in Qt.
                            What exception do you get?

                            I get
                            The inferior stopped because it received a signal from the operating system.
                            Signal name: SIGABRT
                            Signal meaning: Aborted

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #30

                            @jenya7 Please run through debugger and post the stack trace.
                            Also, you should post your current code with enabled viewfinder.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            J 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @jenya7 Please run through debugger and post the stack trace.
                              Also, you should post your current code with enabled viewfinder.

                              J Offline
                              J Offline
                              jenya7
                              wrote on last edited by
                              #31

                              @jsulm said in A camera problem.:

                              @jenya7 Please run through debugger and post the stack trace.
                              Also, you should post your current code with enabled viewfinder.

                              void Camera::setCamera(const QCameraInfo &cameraInfo)
                              {
                                  m_camera.reset(new QCamera(cameraInfo));
                              
                                  connect(m_camera.data(), &QCamera::stateChanged, this, &Camera::updateCameraState);
                                  connect(m_camera.data(), QOverload<QCamera::Error>::of(&QCamera::error), this, &Camera::displayCameraError);
                              
                                  m_mediaRecorder.reset(new QMediaRecorder(m_camera.data()));
                                  connect(m_mediaRecorder.data(), &QMediaRecorder::stateChanged, this, &Camera::updateRecorderState);
                              
                                  m_imageCapture.reset(new QCameraImageCapture(m_camera.data()));
                              
                                  connect(m_mediaRecorder.data(), &QMediaRecorder::durationChanged, this, &Camera::updateRecordTime);
                                  connect(m_mediaRecorder.data(), QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error),
                                          this, &Camera::displayRecorderError);
                              
                                  m_mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Test Title")));
                              
                                  //connect(ui->exposureCompensation, &QAbstractSlider::valueChanged, this, &Camera::setExposureCompensation);
                              
                              //here the exception occurs
                                 QCameraViewfinder *v_finder = new QCameraViewfinder();
                                  //v_finder->setFixedSize(240, 320);
                                  //v_finder->show();
                                  v_finder->setAttribute(Qt::WA_NoSystemBackground);
                                  m_camera->setViewfinder(v_finder);
                              
                                  updateCameraState(m_camera->state());
                                  updateLockStatus(m_camera->lockStatus(), QCamera::UserRequest);
                                  updateRecorderState(m_mediaRecorder->state());
                              
                                  connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &Camera::readyForCapture);
                                  connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &Camera::processCapturedImage);
                                  connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &Camera::imageSaved);
                                  connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error),
                                          this, &Camera::displayCaptureError);
                              
                                  connect(m_imageCapture.data(), &QCameraImageCapture::imageAvailable, this, &Camera::ImageAvailable);
                              
                                  connect(m_camera.data(), QOverload<QCamera::LockStatus, QCamera::LockChangeReason>::of(&QCamera::lockStatusChanged),
                                          this, &Camera::updateLockStatus);
                              
                                  //ui->captureWidget->setTabEnabled(0, (m_camera->isCaptureModeSupported(QCamera::CaptureStillImage)));
                                  //ui->captureWidget->setTabEnabled(1, (m_camera->isCaptureModeSupported(QCamera::CaptureVideo)));
                              
                                  updateCaptureMode(0);
                                  m_camera->start();
                              }
                              

                              and a call stack

                              1  __GI_raise                                                  raise.c      50  0xb5830f14 
                              2  __GI_abort                                                  abort.c      79  0xb581c230 
                              3  QMessageLogger::fatal(const char *, ...) const                               0xb5c1c004 
                              4  QWidgetPrivate::QWidgetPrivate(int)                                          0xb698e204 
                              5  QWidget::QWidget(QWidget *, QFlags<Qt::WindowType>)                          0xb69ab42c 
                              6  QVideoWidget::QVideoWidget(QVideoWidgetPrivate&, QWidget *)                  0xb6f3ed70 
                              7  QCameraViewfinder::QCameraViewfinder(QWidget *)                              0xb6f388f4 
                              8  Camera::setCamera                                           camera.cpp   148 0x5a000        //this line is focused
                              9  Camera::Camera                                              camera.cpp   112 0x599ec    
                              10 __static_initialization_and_destruction_0                   camera.cpp   69  0x5bd58    
                              11 _GLOBAL__sub_I_camera.cpp(void)                             camera.cpp   544 0x5bdb4    
                              12 __libc_csu_init                                                              0xbed54    
                              13 __libc_start_main                                           libc-start.c 264 0xb581c6ac 
                              14 _start        
                              
                              jsulmJ 1 Reply Last reply
                              0
                              • J jenya7

                                @jsulm said in A camera problem.:

                                @jenya7 Please run through debugger and post the stack trace.
                                Also, you should post your current code with enabled viewfinder.

                                void Camera::setCamera(const QCameraInfo &cameraInfo)
                                {
                                    m_camera.reset(new QCamera(cameraInfo));
                                
                                    connect(m_camera.data(), &QCamera::stateChanged, this, &Camera::updateCameraState);
                                    connect(m_camera.data(), QOverload<QCamera::Error>::of(&QCamera::error), this, &Camera::displayCameraError);
                                
                                    m_mediaRecorder.reset(new QMediaRecorder(m_camera.data()));
                                    connect(m_mediaRecorder.data(), &QMediaRecorder::stateChanged, this, &Camera::updateRecorderState);
                                
                                    m_imageCapture.reset(new QCameraImageCapture(m_camera.data()));
                                
                                    connect(m_mediaRecorder.data(), &QMediaRecorder::durationChanged, this, &Camera::updateRecordTime);
                                    connect(m_mediaRecorder.data(), QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error),
                                            this, &Camera::displayRecorderError);
                                
                                    m_mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Test Title")));
                                
                                    //connect(ui->exposureCompensation, &QAbstractSlider::valueChanged, this, &Camera::setExposureCompensation);
                                
                                //here the exception occurs
                                   QCameraViewfinder *v_finder = new QCameraViewfinder();
                                    //v_finder->setFixedSize(240, 320);
                                    //v_finder->show();
                                    v_finder->setAttribute(Qt::WA_NoSystemBackground);
                                    m_camera->setViewfinder(v_finder);
                                
                                    updateCameraState(m_camera->state());
                                    updateLockStatus(m_camera->lockStatus(), QCamera::UserRequest);
                                    updateRecorderState(m_mediaRecorder->state());
                                
                                    connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &Camera::readyForCapture);
                                    connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &Camera::processCapturedImage);
                                    connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &Camera::imageSaved);
                                    connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error),
                                            this, &Camera::displayCaptureError);
                                
                                    connect(m_imageCapture.data(), &QCameraImageCapture::imageAvailable, this, &Camera::ImageAvailable);
                                
                                    connect(m_camera.data(), QOverload<QCamera::LockStatus, QCamera::LockChangeReason>::of(&QCamera::lockStatusChanged),
                                            this, &Camera::updateLockStatus);
                                
                                    //ui->captureWidget->setTabEnabled(0, (m_camera->isCaptureModeSupported(QCamera::CaptureStillImage)));
                                    //ui->captureWidget->setTabEnabled(1, (m_camera->isCaptureModeSupported(QCamera::CaptureVideo)));
                                
                                    updateCaptureMode(0);
                                    m_camera->start();
                                }
                                

                                and a call stack

                                1  __GI_raise                                                  raise.c      50  0xb5830f14 
                                2  __GI_abort                                                  abort.c      79  0xb581c230 
                                3  QMessageLogger::fatal(const char *, ...) const                               0xb5c1c004 
                                4  QWidgetPrivate::QWidgetPrivate(int)                                          0xb698e204 
                                5  QWidget::QWidget(QWidget *, QFlags<Qt::WindowType>)                          0xb69ab42c 
                                6  QVideoWidget::QVideoWidget(QVideoWidgetPrivate&, QWidget *)                  0xb6f3ed70 
                                7  QCameraViewfinder::QCameraViewfinder(QWidget *)                              0xb6f388f4 
                                8  Camera::setCamera                                           camera.cpp   148 0x5a000        //this line is focused
                                9  Camera::Camera                                              camera.cpp   112 0x599ec    
                                10 __static_initialization_and_destruction_0                   camera.cpp   69  0x5bd58    
                                11 _GLOBAL__sub_I_camera.cpp(void)                             camera.cpp   544 0x5bdb4    
                                12 __libc_csu_init                                                              0xbed54    
                                13 __libc_start_main                                           libc-start.c 264 0xb581c6ac 
                                14 _start        
                                
                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #32

                                @jenya7 I'm confused by the code you posted: sometimes you use m_camera. and sometimes m_camera->! How can this even compile?!

                                Try to set a parent on QCameraViewfinder to see whether it makes a difference.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                J 1 Reply Last reply
                                0
                                • jsulmJ jsulm

                                  @jenya7 I'm confused by the code you posted: sometimes you use m_camera. and sometimes m_camera->! How can this even compile?!

                                  Try to set a parent on QCameraViewfinder to see whether it makes a difference.

                                  J Offline
                                  J Offline
                                  jenya7
                                  wrote on last edited by jenya7
                                  #33

                                  @jsulm said in A camera problem.:

                                  @jenya7 I'm confused by the code you posted: sometimes you use m_camera. and sometimes m_camera->! How can this even compile?!

                                  Try to set a parent on QCameraViewfinder to see whether it makes a difference.

                                  Hmm..It's an example from the official Qt/Examples folder. I guess those with a dot - the intrinsic methods, not from a Camera class.

                                  for example - m_camera.reset
                                  from - C:\Qt\5.12.0\mingw73_64\include\QtCore\qscopedpointer.h

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • J jenya7

                                    @jsulm said in A camera problem.:

                                    @jenya7 I'm confused by the code you posted: sometimes you use m_camera. and sometimes m_camera->! How can this even compile?!

                                    Try to set a parent on QCameraViewfinder to see whether it makes a difference.

                                    Hmm..It's an example from the official Qt/Examples folder. I guess those with a dot - the intrinsic methods, not from a Camera class.

                                    for example - m_camera.reset
                                    from - C:\Qt\5.12.0\mingw73_64\include\QtCore\qscopedpointer.h

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #34

                                    @jenya7 No, this belongs to C++ basics: if m_camera is a pointer then you have to use -> if it is not a pointer then you have to use dot. So, what is m_camera in YOUR code?

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    J 1 Reply Last reply
                                    0
                                    • jsulmJ jsulm

                                      @jenya7 No, this belongs to C++ basics: if m_camera is a pointer then you have to use -> if it is not a pointer then you have to use dot. So, what is m_camera in YOUR code?

                                      J Offline
                                      J Offline
                                      jenya7
                                      wrote on last edited by jenya7
                                      #35

                                      @jsulm said in A camera problem.:

                                      @jenya7 No, this belongs to C++ basics: if m_camera is a pointer then you have to use -> if it is not a pointer then you have to use dot. So, what is m_camera in YOUR code?

                                      in camera.h

                                      class Camera : public QMainWindow
                                      {
                                          Q_OBJECT
                                      
                                      public:
                                          Camera(QObject *parent = nullptr);
                                      
                                           void takeImage();
                                      
                                      private slots:
                                          void setCamera(const QCameraInfo &cameraInfo);
                                      
                                          void startCamera();
                                          void stopCamera();
                                      
                                          void record();
                                          void pause();
                                          void stop();
                                          void setMuted(bool);
                                      
                                          void toggleLock();
                                          void displayCaptureError(int, QCameraImageCapture::Error, const QString &errorString);
                                      
                                          void configureCaptureSettings();
                                          void configureVideoSettings();
                                          void configureImageSettings();
                                          void displayRecorderError();
                                          void displayCameraError();
                                      
                                          void updateCameraDevice(QAction *action);
                                      
                                          void updateCameraState(QCamera::State);
                                          void updateCaptureMode();
                                          void updateRecorderState(QMediaRecorder::State state);
                                          void setExposureCompensation(int index);
                                      
                                          void updateRecordTime();
                                      
                                          void processCapturedImage(int requestId, const QImage &img);
                                          void updateLockStatus(QCamera::LockStatus, QCamera::LockChangeReason);
                                      
                                          void displayViewfinder();
                                          void displayCapturedImage();
                                      
                                          void readyForCapture(bool ready);
                                          void imageSaved(int id, const QString &fileName);
                                      
                                      protected:
                                          void keyPressEvent(QKeyEvent *event) override;
                                          void keyReleaseEvent(QKeyEvent *event) override;
                                          void closeEvent(QCloseEvent *event) override;
                                      
                                      private:
                                          Ui::Camera *ui;
                                      
                                          QScopedPointer<QCamera> m_camera;
                                      
                                          QScopedPointer<QCameraImageCapture> m_imageCapture;
                                          QScopedPointer<QMediaRecorder> m_mediaRecorder;
                                      
                                          QImageEncoderSettings m_imageSettings;
                                          QAudioEncoderSettings m_audioSettings;
                                          QVideoEncoderSettings m_videoSettings;
                                          QString m_videoContainerFormat;
                                          bool m_isCapturingImage = false;
                                          bool m_applicationExiting = false;
                                      };
                                      
                                      

                                      It's a private member initialized after the camera found in a constructor.

                                      Camera::Camera(QObject *parent) : QObject(parent) 
                                      {
                                            //some code
                                            if (cameraInfo == QCameraInfo::defaultCamera())
                                                    videoDeviceAction->setChecked(true);
                                      
                                             setCamera(QCameraInfo::defaultCamera());
                                      }
                                      
                                      jsulmJ 1 Reply Last reply
                                      0
                                      • J jenya7

                                        @jsulm said in A camera problem.:

                                        @jenya7 No, this belongs to C++ basics: if m_camera is a pointer then you have to use -> if it is not a pointer then you have to use dot. So, what is m_camera in YOUR code?

                                        in camera.h

                                        class Camera : public QMainWindow
                                        {
                                            Q_OBJECT
                                        
                                        public:
                                            Camera(QObject *parent = nullptr);
                                        
                                             void takeImage();
                                        
                                        private slots:
                                            void setCamera(const QCameraInfo &cameraInfo);
                                        
                                            void startCamera();
                                            void stopCamera();
                                        
                                            void record();
                                            void pause();
                                            void stop();
                                            void setMuted(bool);
                                        
                                            void toggleLock();
                                            void displayCaptureError(int, QCameraImageCapture::Error, const QString &errorString);
                                        
                                            void configureCaptureSettings();
                                            void configureVideoSettings();
                                            void configureImageSettings();
                                            void displayRecorderError();
                                            void displayCameraError();
                                        
                                            void updateCameraDevice(QAction *action);
                                        
                                            void updateCameraState(QCamera::State);
                                            void updateCaptureMode();
                                            void updateRecorderState(QMediaRecorder::State state);
                                            void setExposureCompensation(int index);
                                        
                                            void updateRecordTime();
                                        
                                            void processCapturedImage(int requestId, const QImage &img);
                                            void updateLockStatus(QCamera::LockStatus, QCamera::LockChangeReason);
                                        
                                            void displayViewfinder();
                                            void displayCapturedImage();
                                        
                                            void readyForCapture(bool ready);
                                            void imageSaved(int id, const QString &fileName);
                                        
                                        protected:
                                            void keyPressEvent(QKeyEvent *event) override;
                                            void keyReleaseEvent(QKeyEvent *event) override;
                                            void closeEvent(QCloseEvent *event) override;
                                        
                                        private:
                                            Ui::Camera *ui;
                                        
                                            QScopedPointer<QCamera> m_camera;
                                        
                                            QScopedPointer<QCameraImageCapture> m_imageCapture;
                                            QScopedPointer<QMediaRecorder> m_mediaRecorder;
                                        
                                            QImageEncoderSettings m_imageSettings;
                                            QAudioEncoderSettings m_audioSettings;
                                            QVideoEncoderSettings m_videoSettings;
                                            QString m_videoContainerFormat;
                                            bool m_isCapturingImage = false;
                                            bool m_applicationExiting = false;
                                        };
                                        
                                        

                                        It's a private member initialized after the camera found in a constructor.

                                        Camera::Camera(QObject *parent) : QObject(parent) 
                                        {
                                              //some code
                                              if (cameraInfo == QCameraInfo::defaultCamera())
                                                      videoDeviceAction->setChecked(true);
                                        
                                               setCamera(QCameraInfo::defaultCamera());
                                        }
                                        
                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #36

                                        @jenya7 OK, now it makes sense. Did you try to set parent on the viewfinder?

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        J 1 Reply Last reply
                                        0
                                        • jsulmJ jsulm

                                          @jenya7 OK, now it makes sense. Did you try to set parent on the viewfinder?

                                          J Offline
                                          J Offline
                                          jenya7
                                          wrote on last edited by
                                          #37

                                          @jsulm said in A camera problem.:

                                          @jenya7 OK, now it makes sense. Did you try to set parent on the viewfinder?

                                          That's it - they use the widget int the app. What should I choose as a parent?

                                          jsulmJ 1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved