Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
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 48.0k 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.
  • jsulmJ jsulm

    @jenya7 said in A camera problem.:

    It's not physically allocated

    It is, see the first line in the constructor

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

    @jsulm said in A camera problem.:

    @jenya7 said in A camera problem.:

    It's not physically allocated

    It is, see the first line in the constructor

    It doesn't work

    jsulmJ 1 Reply Last reply
    0
    • J jenya7

      @JonB
      viewfinder = new QCameraViewfinder(); is an empty object, not tied to any widget. in the original example viewfinder is tied to a StackedWidget panel.

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

      @jenya7 said in A camera problem.:

      viewfinder = new QCameraViewfinder(); is an empty object, not tied to any widget.

      It's not "empty". And a widget does not have to be "tied" to another widget. If it is not and you call show() on it it will be shown in its own window, but it should not crash...

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

      J 1 Reply Last reply
      0
      • J jenya7

        @jsulm said in A camera problem.:

        @jenya7 said in A camera problem.:

        It's not physically allocated

        It is, see the first line in the constructor

        It doesn't work

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

        @jenya7 said in A camera problem.:

        It doesn't work

        What doesn't work? I'm sure that line works. Do you call show() after that line or before?

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

        1 Reply Last reply
        0
        • jsulmJ jsulm

          @jenya7 said in A camera problem.:

          viewfinder = new QCameraViewfinder(); is an empty object, not tied to any widget.

          It's not "empty". And a widget does not have to be "tied" to another widget. If it is not and you call show() on it it will be shown in its own window, but it should not crash...

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

          @jsulm said in A camera problem.:

          @jenya7 said in A camera problem.:

          viewfinder = new QCameraViewfinder(); is an empty object, not tied to any widget.

          It's not "empty". And a widget does not have to be "tied" to another widget. If it is not and you call show() on it it will be shown in its own window, but it should not crash...

          I see. I'll try to understand what causes the crash.

          1 Reply Last reply
          0
          • J jenya7

            @JonB
            viewfinder = new QCameraViewfinder(); is an empty object, not tied to any widget. in the original example viewfinder is tied to a StackedWidget panel.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #73

            @jenya7 said in A camera problem.:

            viewfinder = new QCameraViewfinder(); is an empty object, not tied to any widget

            QCameraViewfinder is a QWidget, so don't know what this means. In your case you may need to give it a parent or add it somewhere. I have suggested code you might try before turning to your own code....

            1 Reply Last reply
            0
            • JonBJ JonB

              @jenya7
              What is "not physically allocated", and why do you get an exception on what?

              There is a basic example at https://doc.qt.io/qt-5/qcameraviewfinder.html

              camera = new QCamera;
              
              viewfinder = new QCameraViewfinder();
              viewfinder->show();
              
              camera->setViewfinder(viewfinder);
              
              imageCapture = new QCameraImageCapture(camera);
              
              camera->setCaptureMode(QCamera::CaptureStillImage);
              camera->start();
              

              Did you test whether just this code might work for you?

              You also ought check those m_camera->isCaptureModeSupported(...) I mentioned, else you are whistling in the wind....

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

              @JonB said in A camera problem.:

              @jenya7
              What is "not physically allocated", and why do you get an exception on what?

              There is a basic example at https://doc.qt.io/qt-5/qcameraviewfinder.html
              Did you test whether just this code might work for you?

              You also ought check those m_camera->isCaptureModeSupported(...) I mentioned, else you are whistling in the wind....

              bool supported = m_camera->isCaptureModeSupported(QCamera::CaptureStillImage);
              

              Yes. It's supported.
              I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.
              Is it normal?

              jsulmJ JonBJ 2 Replies Last reply
              0
              • J jenya7

                @JonB said in A camera problem.:

                @jenya7
                What is "not physically allocated", and why do you get an exception on what?

                There is a basic example at https://doc.qt.io/qt-5/qcameraviewfinder.html
                Did you test whether just this code might work for you?

                You also ought check those m_camera->isCaptureModeSupported(...) I mentioned, else you are whistling in the wind....

                bool supported = m_camera->isCaptureModeSupported(QCamera::CaptureStillImage);
                

                Yes. It's supported.
                I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.
                Is it normal?

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

                @jenya7 said in A camera problem.:

                I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.

                Where do you see it and where do you create camera object? Can you please post relevant code?

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

                J 1 Reply Last reply
                0
                • J jenya7

                  @JonB said in A camera problem.:

                  @jenya7
                  What is "not physically allocated", and why do you get an exception on what?

                  There is a basic example at https://doc.qt.io/qt-5/qcameraviewfinder.html
                  Did you test whether just this code might work for you?

                  You also ought check those m_camera->isCaptureModeSupported(...) I mentioned, else you are whistling in the wind....

                  bool supported = m_camera->isCaptureModeSupported(QCamera::CaptureStillImage);
                  

                  Yes. It's supported.
                  I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.
                  Is it normal?

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by JonB
                  #76

                  @jenya7
                  OK, but why not try the example from the docs, in a standalone test program? Not going to say it again.....

                  J 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @jenya7
                    OK, but why not try the example from the docs, in a standalone test program? Not going to say it again.....

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

                    @JonB said in A camera problem.:

                    @jenya7
                    OK, but why not try the example from the docs, in a standalone test program? Not going to say it again.....

                    It runs on Windows machine. Have to arrange some camera....

                    JonBJ 1 Reply Last reply
                    0
                    • J jenya7

                      @JonB said in A camera problem.:

                      @jenya7
                      OK, but why not try the example from the docs, in a standalone test program? Not going to say it again.....

                      It runs on Windows machine. Have to arrange some camera....

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #78

                      @jenya7
                      What runs on Windows machine? It's just sample code, does it not run on whatever platform you are on? You may know better than I, I'll keep quiet now.

                      1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @jenya7 said in A camera problem.:

                        I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.

                        Where do you see it and where do you create camera object? Can you please post relevant code?

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

                        @jsulm said in A camera problem.:

                        @jenya7 said in A camera problem.:

                        I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.

                        Where do you see it and where do you create camera object? Can you please post relevant code?

                        I put a break point in the MainWindow constructor and Camera constructor and see which hits the first.
                        This way it works without errors

                        QCameraViewfinder *v_finder;
                        
                        MainWindow::MainWindow(QWidget *parent) :
                            QMainWindow(parent),
                            ui(new Ui::MainWindow)
                        {
                            v_finder = new QCameraViewfinder(this);
                            v_finder->show();
                        
                            ui->setupUi(this);
                            ui->textEditTerminalTx->installEventFilter(this);
                        }
                        
                        void Camera::setCamera(const QCameraInfo &cameraInfo)
                        {
                               //........................
                        
                             m_camera->setViewfinder(v_finder);
                        
                              //............................
                        }
                        
                        

                        Is it OK?

                        JonBJ 1 Reply Last reply
                        0
                        • J jenya7

                          @jsulm said in A camera problem.:

                          @jenya7 said in A camera problem.:

                          I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.

                          Where do you see it and where do you create camera object? Can you please post relevant code?

                          I put a break point in the MainWindow constructor and Camera constructor and see which hits the first.
                          This way it works without errors

                          QCameraViewfinder *v_finder;
                          
                          MainWindow::MainWindow(QWidget *parent) :
                              QMainWindow(parent),
                              ui(new Ui::MainWindow)
                          {
                              v_finder = new QCameraViewfinder(this);
                              v_finder->show();
                          
                              ui->setupUi(this);
                              ui->textEditTerminalTx->installEventFilter(this);
                          }
                          
                          void Camera::setCamera(const QCameraInfo &cameraInfo)
                          {
                                 //........................
                          
                               m_camera->setViewfinder(v_finder);
                          
                                //............................
                          }
                          
                          

                          Is it OK?

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by JonB
                          #80

                          @jenya7 said in A camera problem.:

                          I put a break point in the MainWindow constructor and Camera constructor and see which hits the first.

                          And what was the result?!

                          I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.

                          At the time your Camera::setCamera() is called, has v_finder = new QCameraViewfinder(this); been executed yet? If not then v_finder in m_camera->setViewfinder(v_finder) will be nullptr....

                          J 1 Reply Last reply
                          1
                          • JonBJ JonB

                            @jenya7 said in A camera problem.:

                            I put a break point in the MainWindow constructor and Camera constructor and see which hits the first.

                            And what was the result?!

                            I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.

                            At the time your Camera::setCamera() is called, has v_finder = new QCameraViewfinder(this); been executed yet? If not then v_finder in m_camera->setViewfinder(v_finder) will be nullptr....

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

                            @JonB said in A camera problem.:

                            @jenya7 said in A camera problem.:

                            I put a break point in the MainWindow constructor and Camera constructor and see which hits the first.

                            And what was the result?!

                            I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.

                            At the time your Camera::setCamera() is called, has v_finder = new QCameraViewfinder(this); been executed yet? If not then v_finder in m_camera->setViewfinder(v_finder) will be nullptr....

                            m_camera->setViewfinder(v_finder) is executed first

                            JonBJ 1 Reply Last reply
                            0
                            • J jenya7

                              @JonB said in A camera problem.:

                              @jenya7 said in A camera problem.:

                              I put a break point in the MainWindow constructor and Camera constructor and see which hits the first.

                              And what was the result?!

                              I see the Camera object is created before MainWindow::MainWindow(QWidget *parent) constructor.

                              At the time your Camera::setCamera() is called, has v_finder = new QCameraViewfinder(this); been executed yet? If not then v_finder in m_camera->setViewfinder(v_finder) will be nullptr....

                              m_camera->setViewfinder(v_finder) is executed first

                              JonBJ Online
                              JonBJ Online
                              JonB
                              wrote on last edited by
                              #82

                              @jenya7
                              Then obviously it is not the right place to put m_camera->setViewfinder(v_finder);.... You cannot execute that line until both m_camera & v_finder have been initialized, so move it somewhere suitable.

                              J 2 Replies Last reply
                              1
                              • JonBJ JonB

                                @jenya7
                                Then obviously it is not the right place to put m_camera->setViewfinder(v_finder);.... You cannot execute that line until both m_camera & v_finder have been initialized, so move it somewhere suitable.

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

                                @JonB said in A camera problem.:

                                @jenya7
                                Then obviously it is not the right place to put m_camera->setViewfinder(v_finder);.... You cannot execute that line until both m_camera & v_finder have been initialized, so move it somewhere suitable.

                                I'll try

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mchinand
                                  wrote on last edited by
                                  #84

                                  It seems your code is largely based on the Camera Example; is that correct? Does that example work for you unmodified?

                                  J 1 Reply Last reply
                                  0
                                  • M mchinand

                                    It seems your code is largely based on the Camera Example; is that correct? Does that example work for you unmodified?

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

                                    @mchinand said in A camera problem.:

                                    It seems your code is largely based on the Camera Example; is that correct? Does that example work for you unmodified?

                                    It's a widget based example. I removed all widget related stuff cause I don't have all these controls for camera operating in my app. I control the camera with commands I type in a terminal.

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • J jenya7

                                      @mchinand said in A camera problem.:

                                      It seems your code is largely based on the Camera Example; is that correct? Does that example work for you unmodified?

                                      It's a widget based example. I removed all widget related stuff cause I don't have all these controls for camera operating in my app. I control the camera with commands I type in a terminal.

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

                                      @jenya7 Come on, the question is whether this example works with your camera or not! Can't you simply try that?

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

                                      J 1 Reply Last reply
                                      3
                                      • jsulmJ jsulm

                                        @jenya7 Come on, the question is whether this example works with your camera or not! Can't you simply try that?

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

                                        @jsulm said in A camera problem.:

                                        @jenya7 Come on, the question is whether this example works with your camera or not! Can't you simply try that?

                                        I'll try tomorrow. I have to get a camera.

                                        well...in the original example I press on Capture Photo and it stays inactive forever.

                                        J.HilkJ 1 Reply Last reply
                                        0
                                        • J Offline
                                          J Offline
                                          jenya7
                                          wrote on last edited by jenya7
                                          #88

                                          How can I pass a default camera instance to use it later?
                                          In camera.h

                                          class Camera : public QMainWindow
                                          {
                                              Q_OBJECT
                                          
                                              public:
                                              Camera();
                                              void Camera::setCamera(const QCameraInfo &cameraInfo);
                                          
                                              const QCameraInfo* default_camera;   
                                          }
                                          

                                          in camera.cpp in a constructor

                                          if (cameraInfo == QCameraInfo::defaultCamera())
                                          {
                                                 default_camera = new QCameraInfo(cameraInfo );
                                                  videoDeviceAction->setChecked(true);
                                          }
                                          

                                          in main.cpp

                                          g_camera.SetCamera(g_camera.default_camera );
                                          

                                          I get
                                          error: reference to type 'const QCameraInfo' could not bind to an lvalue of type 'const QCameraInfo *'

                                          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
                                          • Unsolved