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. MAC QT5.13 delete QCamera class make corruption
QtWS25 Last Chance

MAC QT5.13 delete QCamera class make corruption

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 660 Views
  • 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.
  • M Offline
    M Offline
    mingzhi
    wrote on 8 Jan 2024, 12:17 last edited by
    #1

    I have a USB camera that not needed driver and In my writen code when the USB camera disappear from my computer, I will delete the QCamera class, but when I delete the QCamera, the program cooruption, here is the debug information,the last page is the corruption occur
    1.png
    2.png
    3.png
    4.png
    5.png

    Please helpt me, thanks

    J 1 Reply Last reply 8 Jan 2024, 12:36
    0
    • C Christian Ehrlicher referenced this topic on 8 Jan 2024, 12:23
    • M mingzhi
      8 Jan 2024, 12:17

      I have a USB camera that not needed driver and In my writen code when the USB camera disappear from my computer, I will delete the QCamera class, but when I delete the QCamera, the program cooruption, here is the debug information,the last page is the corruption occur
      1.png
      2.png
      3.png
      4.png
      5.png

      Please helpt me, thanks

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 8 Jan 2024, 12:36 last edited by
      #2

      @mingzhi Maybe you should first call https://doc.qt.io/qt-5/qcamera.html#stop ?

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

      M 1 Reply Last reply 9 Jan 2024, 01:09
      0
      • J jsulm
        8 Jan 2024, 12:36

        @mingzhi Maybe you should first call https://doc.qt.io/qt-5/qcamera.html#stop ?

        M Offline
        M Offline
        mingzhi
        wrote on 9 Jan 2024, 01:09 last edited by
        #3

        @jsulm I try first call stop,no changed,also corruption

        C 1 Reply Last reply 9 Jan 2024, 02:59
        0
        • M mingzhi
          9 Jan 2024, 01:09

          @jsulm I try first call stop,no changed,also corruption

          C Offline
          C Offline
          ChrisW67
          wrote on 9 Jan 2024, 02:59 last edited by
          #4

          @mingzhi Please do not post screen shots when a simple text copy and paste is far more readable.

          How are you detecting that the camera device has gone away?
          Have you called QCamera::unload()?
          What else have you tried?

          M 2 Replies Last reply 9 Jan 2024, 03:13
          0
          • C ChrisW67
            9 Jan 2024, 02:59

            @mingzhi Please do not post screen shots when a simple text copy and paste is far more readable.

            How are you detecting that the camera device has gone away?
            Have you called QCamera::unload()?
            What else have you tried?

            M Offline
            M Offline
            mingzhi
            wrote on 9 Jan 2024, 03:13 last edited by
            #5

            @ChrisW67 In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

            C 1 Reply Last reply 9 Jan 2024, 04:51
            0
            • C ChrisW67
              9 Jan 2024, 02:59

              @mingzhi Please do not post screen shots when a simple text copy and paste is far more readable.

              How are you detecting that the camera device has gone away?
              Have you called QCamera::unload()?
              What else have you tried?

              M Offline
              M Offline
              mingzhi
              wrote on 9 Jan 2024, 03:28 last edited by
              #6

              @ChrisW67 befort delete QCamera , unload, unlock, stop, all those I all try, here is the main create and dropp code, cameraConnected function and cameraDropped function are all slot fuction for cameraconnect signal and cameradrop signal

              void MainWindow::cameraConnected( QList<QCameraInfo> connectedCameras )
              {
              foreach( const QCameraInfo& cameraInfo, connectedCameras ) {
              if( false == fAvailableCameras.contains( cameraInfo ) ) {
              fAvailableCameras.append( cameraInfo );

                      if( nullptr == fCurrentCamera ) {
                          setCamera( cameraInfo );
                      }
                  }
              }
              

              }

              void MainWindow::setCamera( const QCameraInfo& cameraInfo )
              {
              delete fMediaRecorder;
              delete fImageCapture;
              delete fCurrentCamera;
              delete fAudioProbe;

              fMediaRecorder = nullptr;
              fImageCapture = nullptr;
              fCurrentCamera = nullptr;
              fAudioProbe = nullptr;
              
              fCurrentCamera = new QCamera( cameraInfo );
              
              connect( fCurrentCamera, SIGNAL( stateChanged( QCamera::State ) ),
                       this, SLOT( updateCameraState( QCamera::State ) ) );
              connect( fCurrentCamera, SIGNAL( error( QCamera::Error ) ),
                       this, SLOT( cameraError( QCamera::Error ) ) );
              
              fMediaRecorder = new QMediaRecorder( fCurrentCamera );
              connect( fMediaRecorder, SIGNAL( stateChanged( QMediaRecorder::State ) ),
                       this, SLOT( updateRecorderState( QMediaRecorder::State ) ) );
              
              qDebug() << fMediaRecorder->videoSettings().encodingOptions();
              qDebug() << fMediaRecorder->supportedContainers();
              
              fImageCapture = new QCameraImageCapture( fCurrentCamera );
              
              connect( fMediaRecorder, SIGNAL( durationChanged( qint64 ) ),
                       this, SLOT( updateRecordTime( qint64 ) ) );
              connect( fMediaRecorder, SIGNAL( error( QMediaRecorder::Error ) ),
                       this, SLOT( recorderError( QMediaRecorder::Error ) ) );
              
              fMediaRecorder->setMetaData( QMediaMetaData::Title, QVariant( QLatin1String( "SurgiCam" ) ) );
              
              //connect( ui->exposureCompensation, SIGNAL(valueChanged(int)), SLOT(setExposureCompensation(int))) ;
              
              fCurrentCamera->setViewfinder( fCameraViewfinder->videoSurface() );
              
              fCurrentCamera->imageProcessing()->setWhiteBalanceMode( QCameraImageProcessing::WhiteBalanceManual );
              fCurrentCamera->imageProcessing()->setManualWhiteBalance( 50 );
              fCurrentCamera->imageProcessing()->setBrightness( 0 );
              fCurrentCamera->imageProcessing()->setContrast( 0 );
              fCurrentCamera->imageProcessing()->setSaturation( 0 );
              fCurrentCamera->imageProcessing()->setSharpeningLevel( 0 );
              fCurrentCamera->imageProcessing()->setDenoisingLevel( 0 );
              
              fAudioProbe = new QAudioProbe();
              
              if( false == fAudioProbe->setSource( fCurrentCamera ) ) {
                  connect( fAudioProbe, SIGNAL( audioBufferProbed( QAudioBuffer ) ), this, SLOT( updateAudioLevel( QAudioBuffer ) ) );
              }
              
              fIsFullScreen = false;
              //connect( fActionToggleFullScreen, SIGNAL( toggled( bool ) ), fCameraViewfinder, SLOT( setFullScreen( bool ) ) );
              connect( fActionToggleFullScreen, SIGNAL( toggled( bool ) ), this, SLOT( toggleFullScreenMode( bool ) ) );
              connect( fActionToggleFullScreenNative, SIGNAL( toggled( bool ) ), this, SLOT( toggleFullScreenMode( bool ) ) );
              
              updateCameraState( fCurrentCamera->state() );
              updateCameraLockState( fCurrentCamera->lockStatus(), QCamera::UserRequest );
              updateRecorderState( fMediaRecorder->state() );
              
              connect( fImageCapture, SIGNAL( readyForCaptureChanged( bool ) ),
                       this, SLOT( readyForCapture( bool ) ) );
              connect( fImageCapture, SIGNAL( imageCaptured( int, QImage ) ),
                       this, SLOT( capturedImage( int, QImage ) ) );
              connect( fImageCapture, SIGNAL( imageSaved( int, QString ) ),
                       this, SLOT( imageSaved( int, QString ) ) );
              connect( fImageCapture, SIGNAL( error( int, QCameraImageCapture::Error, QString ) ),
                       this, SLOT( captureError( int, QCameraImageCapture::Error, QString ) ) );
              
              connect( fCurrentCamera, SIGNAL( lockStatusChanged( QCamera::LockStatus, QCamera::LockChangeReason ) ),
                       this, SLOT( updateCameraLockState( QCamera::LockStatus, QCamera::LockChangeReason ) ) );
              

              // ui->captureWidget->setTabEnabled(0, (camera->isCaptureModeSupported(QCamera::CaptureStillImage)));
              // ui->captureWidget->setTabEnabled(1, (camera->isCaptureModeSupported(QCamera::CaptureVideo)));

              // updateCaptureMode();

              fCurrentCamera->load();
              
              qDebug() << "Supported audio codec: " << fMediaRecorder->supportedAudioCodecs();
              qDebug() << "Supported audio sample-rate: " << fMediaRecorder->supportedAudioSampleRates();
              qDebug() << "Supported video codec: " << fMediaRecorder->supportedVideoCodecs();
              qDebug() << "Supported video resolutions: " << fImageCapture->supportedResolutions();
              qDebug() << "Supported video frame-rate: " << fMediaRecorder->supportedFrameRates();
              
              fCurrentCamera->setCaptureMode( QCamera::CaptureStillImage );
              
              fCurrentCamera->start();
              fCurrentCameraInfo = cameraInfo;
              
              fMediaPlayerWidget->stop();
              fStackedPlayersWidget->setCurrentIndex( 1 );
              fWaitingForCameraWidget->stop();
              
              fVideoEncoderSettings = fMediaRecorder->videoSettings();
              fAudioEncoderSettings = fMediaRecorder->audioSettings();
              fVideoContainerFormat = QString();
              
              fSupportedResolution.clear();
              QList<QSize> supportedResolution = fImageCapture->supportedResolutions();
              
              for( int i = supportedResolution.count() - 1; i >= 0; --i ) {
                  fSupportedResolution.append( supportedResolution[i] );
              
                  if( 4 == fSupportedResolution.count() ) {
                      break;
                  }
              }
              
              if( fCurrentCameraInfo.description().startsWith( fSupportedCameraDescriptions[0] ) ) {
                  fSelectedResolution = 0;
              }
              else {
                  fSelectedResolution = 3;
              }
              
              for( int i = 0; i < 4; ++i ) {
                  fActionResolutions[i]->setText( QString( "%1 x %2" ).arg( fSupportedResolution[i].width() ).arg( fSupportedResolution[i].height() ) );
              
                  fActionResolutions[i]->setChecked( i == fSelectedResolution );
              }
              
              fSelectedRotation = 0;
              
              for( int i = 0; i < 4; ++i ) {
                  fActionRotations[i]->setChecked( i == fSelectedRotation );
              }
              
              fVideoEncoderSettings.setResolution( fSupportedResolution[fSelectedResolution] );
              fMediaRecorder->setEncodingSettings( fAudioEncoderSettings, fVideoEncoderSettings );
              
              fLiveMode = true;
              fInformationFileNameEdit->setText( fLiveFileName );
              fInformationDoctorNameEdit->setText( fLiveDoctorName );
              fInformationPatientNameEdit->setText( fLivePatientName );
              fInformationHospitalNameEdit->setText( fLiveHospitalName );
              fInformationCommentEdit->setText( fLiveComment );
              
              setupIdleUIState();
              

              }
              void MainWindow::cameraDropped( QList<QCameraInfo> droppedCameras )
              {
              bool dropCurrent = false;

              foreach( const QCameraInfo& cameraInfo, droppedCameras ) {
                  if( false != fAvailableCameras.removeOne( cameraInfo ) ) {
                      if( nullptr != fCurrentCamera && cameraInfo == fCurrentCameraInfo ) {
                          if( nullptr != fMediaRecorder ) {
                              if( QMediaRecorder::RecordingState == fMediaRecorder->state() ) {
                                  fMediaRecorder->stop();
                              }
              
                              if( nullptr != fFileSplitTask ) {
                                  fFileSplitTask->abort();
                                  fFileSplitTask = nullptr;
                              }
                          }
              
                          fVideoCaptureAnimationLabel->toggle( false );
                          fVideoCaptureButton->setChecked( false );
              
                          delete fMediaRecorder;
                          delete fImageCapture;
                          delete fCurrentCamera;
                          delete fAudioProbe;
              
                          fMediaRecorder = nullptr;
                          fImageCapture = nullptr;
                          fCurrentCamera = nullptr;
                          fAudioProbe = nullptr;
              
                          fCurrentCameraInfo = QCameraInfo();
              
                          fMediaPlayerWidget->stop();
                          fStackedPlayersWidget->setCurrentIndex( 0 );
                          fWaitingForCameraWidget->start();
              
                          setupInvaildUIState();
              
                          dropCurrent = true;
                      }
                  }
              }
              
              if( false != dropCurrent ) {
                  if( 0 < fAvailableCameras.count() ) {
                      setCamera( fAvailableCameras[0] );
                  }
              }
              

              }

              1 Reply Last reply
              0
              • M mingzhi
                9 Jan 2024, 03:13

                @ChrisW67 In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

                C Offline
                C Offline
                ChrisW67
                wrote on 9 Jan 2024, 04:51 last edited by
                #7

                @mingzhi said in MAC QT5.13 delete QCamera class make corruption:

                In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

                So, you will not detect the absence of the camera until some indeterminate time after the device has actually gone. I do not know whether your camera object pointer will still be valid at that point in time.

                Have you looked at the QCamera::statusChanged() signal to see what that Qt is telling you before the crash?

                M 7 Replies Last reply 9 Jan 2024, 06:07
                0
                • C ChrisW67
                  9 Jan 2024, 04:51

                  @mingzhi said in MAC QT5.13 delete QCamera class make corruption:

                  In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

                  So, you will not detect the absence of the camera until some indeterminate time after the device has actually gone. I do not know whether your camera object pointer will still be valid at that point in time.

                  Have you looked at the QCamera::statusChanged() signal to see what that Qt is telling you before the crash?

                  M Offline
                  M Offline
                  mingzhi
                  wrote on 9 Jan 2024, 06:07 last edited by
                  #8

                  @ChrisW67 but in windows the code run normally

                  1 Reply Last reply
                  0
                  • C ChrisW67
                    9 Jan 2024, 04:51

                    @mingzhi said in MAC QT5.13 delete QCamera class make corruption:

                    In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

                    So, you will not detect the absence of the camera until some indeterminate time after the device has actually gone. I do not know whether your camera object pointer will still be valid at that point in time.

                    Have you looked at the QCamera::statusChanged() signal to see what that Qt is telling you before the crash?

                    M Offline
                    M Offline
                    mingzhi
                    wrote on 9 Jan 2024, 06:30 last edited by
                    #9

                    @ChrisW67 if before delete QCamera I used stop and load the status is:

                    1 Reply Last reply
                    0
                    • C ChrisW67
                      9 Jan 2024, 04:51

                      @mingzhi said in MAC QT5.13 delete QCamera class make corruption:

                      In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

                      So, you will not detect the absence of the camera until some indeterminate time after the device has actually gone. I do not know whether your camera object pointer will still be valid at that point in time.

                      Have you looked at the QCamera::statusChanged() signal to see what that Qt is telling you before the crash?

                      M Offline
                      M Offline
                      mingzhi
                      wrote on 9 Jan 2024, 06:40 last edited by
                      #10

                      @ChrisW67 if before delete QCamera I use stop and unload as the follow:

                      (fCurrentCamera is a QCamera class)
                      fCurrentCamera->stop(); ---------( QCamera::statusChanged() ->LoadedState)
                      fCurrentCamera->unload(); ---------( QCamera::statusChanged() ->UnloadedState)
                      delete fCurrentCamera; ---------(crash)

                      and if I not used stop and unload to delete QCamera directly The QCamera::statusChanged() will not happened if I out USB Camera

                      1 Reply Last reply
                      0
                      • C ChrisW67
                        9 Jan 2024, 04:51

                        @mingzhi said in MAC QT5.13 delete QCamera class make corruption:

                        In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

                        So, you will not detect the absence of the camera until some indeterminate time after the device has actually gone. I do not know whether your camera object pointer will still be valid at that point in time.

                        Have you looked at the QCamera::statusChanged() signal to see what that Qt is telling you before the crash?

                        M Offline
                        M Offline
                        mingzhi
                        wrote on 9 Jan 2024, 06:50 last edited by
                        #11

                        @ChrisW67 sorry I also test now, if I not used stop and unload to delete QCamera directly The QCamera::statusChanged() will be UnloadedState after I use delete QCamera and then crash, but the Crash occurred during the delete process and before I delete QCamera I have detected the Camera removed from my computer

                        1 Reply Last reply
                        0
                        • C ChrisW67
                          9 Jan 2024, 04:51

                          @mingzhi said in MAC QT5.13 delete QCamera class make corruption:

                          In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

                          So, you will not detect the absence of the camera until some indeterminate time after the device has actually gone. I do not know whether your camera object pointer will still be valid at that point in time.

                          Have you looked at the QCamera::statusChanged() signal to see what that Qt is telling you before the crash?

                          M Offline
                          M Offline
                          mingzhi
                          wrote on 9 Jan 2024, 07:01 last edited by
                          #12

                          @ChrisW67 I am not delete QCamera in other place, so the pointer shoulde be valid

                          1 Reply Last reply
                          0
                          • C ChrisW67
                            9 Jan 2024, 04:51

                            @mingzhi said in MAC QT5.13 delete QCamera class make corruption:

                            In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

                            So, you will not detect the absence of the camera until some indeterminate time after the device has actually gone. I do not know whether your camera object pointer will still be valid at that point in time.

                            Have you looked at the QCamera::statusChanged() signal to see what that Qt is telling you before the crash?

                            M Offline
                            M Offline
                            mingzhi
                            wrote on 9 Jan 2024, 07:16 last edited by
                            #13

                            @ChrisW67and in my debug picture the QCamera Destructor function occur, so the pointer shoulde vaild

                            1 Reply Last reply
                            0
                            • C ChrisW67
                              9 Jan 2024, 04:51

                              @mingzhi said in MAC QT5.13 delete QCamera class make corruption:

                              In the Init ,I first use QCameraInfo class to finde all avaliable cameraInfo, and create a Qcamera class which I want camerInfo and add this cameraInfo to a QList, then create a Timertask to detect QCameraInfo and when the QCameraInfo::avaliables() doesn't have the QList's camerainfo, I send a signal to slot, in slot I delete QCamera

                              So, you will not detect the absence of the camera until some indeterminate time after the device has actually gone. I do not know whether your camera object pointer will still be valid at that point in time.

                              Have you looked at the QCamera::statusChanged() signal to see what that Qt is telling you before the crash?

                              M Offline
                              M Offline
                              mingzhi
                              wrote on 9 Jan 2024, 09:36 last edited by
                              #14

                              @ChrisW67 sorry, I used Qt 5.15

                              1 Reply Last reply
                              0

                              1/14

                              8 Jan 2024, 12:17

                              • Login

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