我是靠谱客的博主 天真翅膀,这篇文章主要介绍Qt Error : 在子线程中使用QMediaPlayer::setMedia() 设置时一直报错 : ASSERT failure in QCoreApplication.....,现在分享给大家,希望可以做个参考。
运行时报错 : ASSERT failure in QCoreApplication::sendEvent: “Cannot send events to objects owned by a different thread. Current thread 0x0x128c05a8. Receiver ‘’ (of type ‘DirectShowIOReader’) was created in thread 0x0x20c6eeb0”。
有道翻译:在QCoreApplication::sendEvent 中 ASSERT 失败:“不能发送事件到不同线程拥有的对象。” 当前线程0 x0x1f1105a8。 接收器"(类型’ directshowiereader ')被创建在线程0x0x20c402e8“
原因:发送事件的对象 与 接收事件的对象 所处线程不同
sendEvent:Current thread 0x0x128c05a8
Receiver was created in thread 0x0x20c6eeb0
解决:通过发信号方式调用槽函数。
#include "SoundPlayer.h"
CSoundPlayer::CSoundPlayer(QObject *parent)
: QObject(parent)
, m_bFlag(false)
{
// m_pMediaPlayer = new QMediaPlayer(this); // error
m_pMediaPlayer = new QMediaPlayer(); // true
m_pMediaPlayer->setMedia(QUrl("qrc:/sounds/Sounds/voice00.mp3"));
connect(m_pMediaPlayer,&QMediaPlayer::stateChanged,this,&CSoundPlayer::__onStateChanged);
connect(&m_Timer,&QTimer::timeout,this,&CSoundPlayer::__onTimerOut);
connect(this,&CSoundPlayer::__signalSetMedia,m_pMediaPlayer,&QMediaPlayer::setMedia);
this->moveToThread(&m_Thread);
m_Timer.moveToThread(&m_Thread);
}
void CSoundPlayer::__setMediaPlayerAudio(QString strAudioUrl)
{
// m_pMediaPlayer->setMedia(QUrl(strAudioUrl)); // error 直接设置
emit __signalSetMedia(QUrl(strAudioUrl),NULL); // ture 通过信号方式进行setMedia()操作
}
最后
以上就是天真翅膀最近收集整理的关于Qt Error : 在子线程中使用QMediaPlayer::setMedia() 设置时一直报错 : ASSERT failure in QCoreApplication.....的全部内容,更多相关Qt内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复