Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A camera problem.
Qt 6.12 LTS is out! See what's new in the release blog

A camera problem.

Scheduled Pinned Locked Moved Unsolved General and Desktop
91 Posts 7 Posters 46.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.
  • 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
                          • J jenya7

                            @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 Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #38

                            @jenya7 Do you have any other UI/widgets in your application?

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

                            J 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @jenya7 Do you have any other UI/widgets in your application?

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

                              @jsulm said in A camera problem.:

                              @jenya7 Do you have any other UI/widgets in your application?

                              well...I can put one just for debug sake. right now it's a window with a text box for a command line receiving.

                              I did so

                              QWidget *viewfinderPage;
                              viewfinderPage = new QWidget();
                              v_finder = new QCameraViewfinder(viewfinderPage);
                              

                              and I get the same exception on
                              viewfinderPage = new QWidget();

                              jsulmJ 1 Reply Last reply
                              0
                              • J jenya7

                                @jsulm said in A camera problem.:

                                @jenya7 Do you have any other UI/widgets in your application?

                                well...I can put one just for debug sake. right now it's a window with a text box for a command line receiving.

                                I did so

                                QWidget *viewfinderPage;
                                viewfinderPage = new QWidget();
                                v_finder = new QCameraViewfinder(viewfinderPage);
                                

                                and I get the same exception on
                                viewfinderPage = new QWidget();

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

                                @jenya7 said in A camera problem.:

                                and I get the same exception on
                                viewfinderPage = new QWidget();

                                You get same crash if you instanciate a QWidget?
                                Then something is really broken in your setup.
                                Can you build and execute a simple Qt widget application?

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

                                J 1 Reply Last reply
                                0
                                • jsulmJ jsulm

                                  @jenya7 said in A camera problem.:

                                  and I get the same exception on
                                  viewfinderPage = new QWidget();

                                  You get same crash if you instanciate a QWidget?
                                  Then something is really broken in your setup.
                                  Can you build and execute a simple Qt widget application?

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

                                  @jsulm said in A camera problem.:

                                  @jenya7 said in A camera problem.:

                                  and I get the same exception on
                                  viewfinderPage = new QWidget();

                                  You get same crash if you instanciate a QWidget?
                                  Then something is really broken in your setup.
                                  Can you build and execute a simple Qt widget application?

                                  actually viewfinderPage is null pointed. I have to create it. I'll try.

                                  1 Reply Last reply
                                  0
                                  • J Offline
                                    J Offline
                                    jenya7
                                    wrote on last edited by jenya7
                                    #42

                                    well...I added in a main window

                                    QCameraViewfinder *m_viewfinder =  new QCameraViewfinder(this);
                                    
                                    

                                    and then in camera class

                                    camera->setViewfinder(m_viewfinder );
                                    

                                    But still get the message - "Image Capture Error: Camera not ready"
                                    I get it on
                                    m_imageCapture->capture();
                                    When I try to go into capture() - I can't - the source unavailable, can not debug it to see why m_imageCapture decides the camera isn't ready.

                                    1 Reply Last reply
                                    0
                                    • B Offline
                                      B Offline
                                      Bonnie
                                      wrote on last edited by
                                      #43

                                      According to https://doc.qt.io/qt-5/qcamera.html#State-enum :

                                      In the active state as soon as camera is started the viewfinder displays video frames and the camera is ready for capture.
                                      

                                      So capture should not be called right after start.
                                      After calling start, you should asynchronously wait until the state turns to Active before performing any capturing.

                                      J 1 Reply Last reply
                                      3
                                      • B Bonnie

                                        According to https://doc.qt.io/qt-5/qcamera.html#State-enum :

                                        In the active state as soon as camera is started the viewfinder displays video frames and the camera is ready for capture.
                                        

                                        So capture should not be called right after start.
                                        After calling start, you should asynchronously wait until the state turns to Active before performing any capturing.

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

                                        @Bonnie said in A camera problem.:

                                        According to https://doc.qt.io/qt-5/qcamera.html#State-enum :

                                        In the active state as soon as camera is started the viewfinder displays video frames and the camera is ready for capture.
                                        

                                        So capture should not be called right after start.
                                        After calling start, you should asynchronously wait until the state turns to Active before performing any capturing.

                                        so I did

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

                                        it's never ready. never gets out of while.

                                        1 Reply Last reply
                                        0
                                        • SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #45

                                          Hi,

                                          Your tight loop does not allow Qt's event loop to run. You should either use an event loop to "block" the execution or properly implement this through signals and slots.

                                          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
                                          2

                                          • Login

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