A camera problem.
-
@J-Hilk said in A camera problem.:
@jenya7
do you call show() on your viewfinder instance ? It will probably never change its state, if the viewfinder is not "visible"It can be an issue.
Although I create an object in mainwindow.cppQCameraViewfinder *v_finder; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { v_finder= new QCameraViewfinder(this); ui->setupUi(this); ui->textEditTerminalTx->installEventFilter(this); }
It's not physically allocated. The app wasn't suppose to have such widget.
So on v_finder->show() I get an exception.
Is it possible to emulate the viewfinder ? -
@J-Hilk said in A camera problem.:
@jenya7
do you call show() on your viewfinder instance ? It will probably never change its state, if the viewfinder is not "visible"It can be an issue.
Although I create an object in mainwindow.cppQCameraViewfinder *v_finder; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { v_finder= new QCameraViewfinder(this); ui->setupUi(this); ui->textEditTerminalTx->installEventFilter(this); }
It's not physically allocated. The app wasn't suppose to have such widget.
So on v_finder->show() I get an exception.
Is it possible to emulate the viewfinder ?@jenya7 said in A camera problem.:
It's not physically allocated
It is, see the first line in the constructor
-
@J-Hilk said in A camera problem.:
@jenya7
do you call show() on your viewfinder instance ? It will probably never change its state, if the viewfinder is not "visible"It can be an issue.
Although I create an object in mainwindow.cppQCameraViewfinder *v_finder; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { v_finder= new QCameraViewfinder(this); ui->setupUi(this); ui->textEditTerminalTx->installEventFilter(this); }
It's not physically allocated. The app wasn't suppose to have such widget.
So on v_finder->show() I get an exception.
Is it possible to emulate the viewfinder ?@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.... -
@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.... -
@jenya7 said in A camera problem.:
It's not physically allocated
It is, see the first line in the constructor
@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
-
@JonB
viewfinder = new QCameraViewfinder(); is an empty object, not tied to any widget. in the original example viewfinder is tied to a StackedWidget panel.@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...
-
@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
@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?
-
@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...
@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.
-
@JonB
viewfinder = new QCameraViewfinder(); is an empty object, not tied to any widget. in the original example viewfinder is tied to a StackedWidget panel.@jenya7 said in A camera problem.:
viewfinder = new QCameraViewfinder(); is an empty object, not tied to any widget
QCameraViewfinder
is aQWidget
, 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.... -
@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....@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? -
@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?@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?
-
@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? -
@jenya7
OK, but why not try the example from the docs, in a standalone test program? Not going to say it again..... -
@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....
-
@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?
@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 errorsQCameraViewfinder *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?
-
@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 errorsQCameraViewfinder *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?
@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, hasv_finder = new QCameraViewfinder(this);
been executed yet? If not thenv_finder
inm_camera->setViewfinder(v_finder)
will benullptr
.... -
@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, hasv_finder = new QCameraViewfinder(this);
been executed yet? If not thenv_finder
inm_camera->setViewfinder(v_finder)
will benullptr
....@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, hasv_finder = new QCameraViewfinder(this);
been executed yet? If not thenv_finder
inm_camera->setViewfinder(v_finder)
will benullptr
....m_camera->setViewfinder(v_finder) is executed first
-
@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, hasv_finder = new QCameraViewfinder(this);
been executed yet? If not thenv_finder
inm_camera->setViewfinder(v_finder)
will benullptr
....m_camera->setViewfinder(v_finder) is executed first
-
@jenya7
Then obviously it is not the right place to putm_camera->setViewfinder(v_finder);
.... You cannot execute that line until bothm_camera
&v_finder
have been initialized, so move it somewhere suitable. -
It seems your code is largely based on the Camera Example; is that correct? Does that example work for you unmodified?