标题:Phonon模块无法循环播放,MessageBox也很奇怪
作者:ycyu1455
日期:2017-12-16 19:29
内容:
Phonon::MediaObject mediaObject(this);
mediaObject.setCurrentSource(Phonon::MediaSource(bellString));
Phonon::AudioOutput audioOutput(Phonon::MusicCategory, this);
Phonon::Path path = Phonon::createPath(&mediaObject, &audioOutput);//关联MediaObject、AudioOutput
audioOutput.setVolume(tySliderValus);
mediaObject.play();
connect(&mediaObject,SIGNAL(finished()),SLOT(play())) ;
QTimer::singleShot(500000, &mediaObject, SLOT(stop()));
QMessageBox * MessageBox =new QMessageBox();
MessageBox->setWindowTitle("闹钟~~~");
MessageBox->setText(QString("%1 %2").arg(timeString).arg(nOte));
MessageBox->exec();
MessageBox这个消息框关闭后会把音乐停了,这是为什么,我把红色部分的代码删除了,音乐居然也不播放了
#1 [uidab 12-19 08:09]
变量作用域
#2 [yanwuyue 12-19 08:43]
mediaObject 是局部变量,函数结束就析构了, MessageBox->exec();是阻塞式函数,一旦关闭,作用域就结束了