문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top