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
Forum Updated to NodeBB v4.3 + New Features

MAC QT5.13 delete QCamera class make corruption

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 900 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.
  • jsulmJ jsulm

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

    M Offline
    M Offline
    mingzhi
    wrote on last edited by
    #3

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

    C 1 Reply Last reply
    0
    • M mingzhi

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

      C Offline
      C Offline
      ChrisW67
      wrote on 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
      0
      • C ChrisW67

        @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 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
        0
        • C ChrisW67

          @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 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

            @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 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
            0
            • C ChrisW67

              @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 last edited by
              #8

              @ChrisW67 but in windows the code run normally

              1 Reply Last reply
              0
              • C ChrisW67

                @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 last edited by
                #9

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

                1 Reply Last reply
                0
                • C ChrisW67

                  @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 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

                    @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 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

                      @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 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

                        @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 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

                          @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 last edited by
                          #14

                          @ChrisW67 sorry, I used Qt 5.15

                          1 Reply Last reply
                          0

                          • Login

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