Qt的:如何播放声音不用其他阻塞主线程? [英] Qt: How to play sound witout blocking main thread?

查看:2243
本文介绍了Qt的:如何播放声音不用其他阻塞主线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有Qt中的一个简单的方法来播放声音,而不会阻塞主线程?

我知道我normaly应该开始一个单独的线程来做到这一点。但是,也许有捷径? :)

感谢您的帮助。


解决方案

的http:// doc.qt.nokia.com/latest/qsound.html


  

Qt提供的GUI应用程序中最常用所需的音频操作:异步播放声音文件。这是使用静态的戏最容易实现的()函数:


  QSound的发挥::(mysounds / bells.wav);

看起来这是一个异步操作,所以它不应该阻止你的主线程。

I'm wondering is there a simple way in Qt to play sound without blocking the main thread ?

I know that normaly I should start a seperate thread to do this. But maybe there is a shortcut ? :)

Thanks for help.

解决方案

http://doc.qt.nokia.com/latest/qsound.html

Qt provides the most commonly required audio operation in GUI applications: asynchronously playing a sound file. This is most easily accomplished using the static play() function:

 QSound::play("mysounds/bells.wav");

It seems like this is an asynchronous operation, so it shouldn't block your main thread.

这篇关于Qt的:如何播放声音不用其他阻塞主线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆