1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include "soundplayer.h" QMap<QString, QSound *> SoundPlayer::map; QSound *SoundPlayer::current = 0; void SoundPlayer::play(const QString &filename) { if (current && !current->isFinished()) current->stop(); if (map.contains(filename)) current = map.value(filename); else { current = new QSound(filename); map[filename] = current; } current->play(); }