Question

I want to compile some old QT project with QT 5.2.1 and have many trouble, one of which is QSound problem:

if(!QSound::isAvailable()) {
    ui.grpSounds->setEnabled(false);
    ui.grpSounds->setTitle(tr("Sounds (Not Available)"));
}

error: 'isAvailable' is not a member of 'QSound'

will anyone help me? I am completely newbie with Qt. Thank you.

Was it helpful?

Solution

If you want to notify the user whether or not sounds can be played then your best bet is QAudioDeviceInfo. You can query for available input or output devices using the static method

QList<QAudioDeviceInfo> QAudioDeviceInfo::availableDevices(QAudio::Mode mode)

For instance you can replace QSound::isAvailable() by

!QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).isEmpty()

Edit:

QSound was part of the gui module, but now is part of the multimedia module (which make more sense). You need take a look at the changes in multimedia modules from Qt4 to Qt5 for more info. You may also want to look at QSoundEffect, which seems to have a richer API

OTHER TIPS

According to class reference, Qt 5.2 don't have Sound::isAvailable() static method http://qt-project.org/doc/qt-5/qsound.html

It was in Qt4.8

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top