Playing WAV Files in Qt 5.3

2019-08-05 08:27发布

I've been trying to make an alarm clock lately in Qt since school is coming up. Anyhow, I made on about a year ago using an old version of Qt, and used Phonon for the sound, but Phonon is no longer included in Qt. I've tried using QtMultimedia, but it doesn't seem to work because I am missing the library file. If you know a way to play an audio file in Qt, it would be greatly appreciated if you tell me how.

标签: c++ qt audio
2条回答
趁早两清
2楼-- · 2019-08-05 08:54

QSound can play wav files, QMultimedia is too heavy for this simple job. QSound is perfect solution for short alarm signals. The simplest way is to use static method play()

QSound::play("pathToFile");
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-08-05 09:03

QSound class from the QtMultimedia module provides the necessary functionality to play .wav files.

As for the missing library file, I suggest you reinstall Qt5.3 with the online installer. The Multimedia module should be installed automatically (or it may be optional).

Otherwise, if you are building from source, make sure to include the QtMultimedia library.

查看更多
登录 后发表回答