Yezan Rafed
Yezan Rafed

Reputation: 782

QAudioRecorder crashes on stop

I am trying to create a simple audio recorder, so I'm using the QAudioRecorder class.

The recording works fine but after 3, 4 or 5 recordings, the program crashes when calling QAudioRecorder::stop().

I couldn't get any thing from the debugger, because it's stuck in an infinite loop.

AudioManager class :

class AudioManager : public QObject
{
    Q_OBJECT

    // ... some properties
      
    QAudioRecorder* audioRecorder;

public:
    AudioManager();

    // ... some other methods

public slots:
    void record();
    void stopRecord();

signals:
    void recordStarted();
    void recordStoped();

    // ...
};

here is my record method :

void AudioRecorder::record() 
{        
    audioRecorder->setOutputLocation(QUrl::fromLocalFile(fileName));
   
    // to make sure the recorder is ready to record
    if ( audioRecorder->status() == QMediaRecorder::LoadedStatus ||
         audioRecorder->status() == QMediaRecorder::FinalizingStatus )
    {
        audioRecorder->record();
        if ( audioRecorder->state() == QMediaRecorder::RecordingState )
        {
            emit recordStarted(); // emit a signal to the UI
        }
    }
}

And here is the stop record method :

void AudioRecorder::stopRecord()
{
    if ( audioRecorder->state() == QMediaRecorder::RecordingState )
    {
        audioRecorder->stop(); // crash occurs here, stuck in a infinite loop!
        if ( audioRecorder->status() == QMediaRecorder::FinalizingStatus ||
             audioRecorder->status() == QMediaRecorder::LoadedStatus)
        {
            emit recordStopped();
        }
    }
}

Upvotes: 1

Views: 101

Answers (0)

Related Questions