Improve the windows respond by using thread
[QFreeRecite.git] / src / gui / WinSpeaker.cpp
blob0ad493b369d04396f6a71d21cd836f75b28dd9f1
1 #include <windows.h>
2 #include <cstdio>
3 #include "WinSpeaker.h"
5 //By default, mutex should be nonrecursive.
6 QMutex WinSpeaker::mutex(QMutex::NonRecursive);
8 WinSpeaker::WinSpeaker(QObject *parent)
9 : QThread(parent) {
10 /*Do Nothing Here!*/
13 bool WinSpeaker::speak(const std::string &wordFile) {
14 if(!mutex.tryLock()){
15 return false;
16 }else {
17 word = wordFile;
18 start();
19 return true;
23 void WinSpeaker::run() {
24 PlaySound(word.c_str(), 0, SND_FILENAME);
25 mutex.unlock();