通过槽和信号在不同线程中的两个qt对象之间进行通信
Communicate between two qt objects in different threads through slots and signals
我想连接两个在不同线程中运行的 qt 对象。(download_webm 和播放器)
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
DownloadWebm *download_webm;
MyThread *DownloadWebm_Thread = new MyThread(download_webm);
DownloadWebm_Thread->start();
LinuWebmPlayer *player = new LinuWebmPlayer(argv[1],0);
QObject::connect(download_webm,SIGNAL(send_packege(Video_Bytes_Package)),player,SLOT(play()));
player->show();
return app.exec();
}
MyThread 头文件:
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <qthread.h>
#include <downloadwebm.h>
class MyThread : public QThread
{
Q_OBJECT
public:
MyThread(DownloadWebm *&we);
MyThread();
DownloadWebm **getWebm() const;
protected:
DownloadWebm **webm;
void run();
};
#endif // MYTHREAD_H
和 cpp:
#include "mythread.h"
MyThread::MyThread()
{
}
DownloadWebm **MyThread::getWebm() const
{
return webm;
}
MyThread::MyThread(DownloadWebm *&we)
{
webm = &we;
}
void MyThread::run()
{
*webm = new DownloadWebm("http://trilulilu.de.de/recstreamingsource?movie=3860","asd");
}
如果我从 main 注释 QObject::connect 行,一切正常,关于 qt 中线程之间的通信,我是否遗漏了什么?
................................................ .........
我想连接两个在不同线程中运行的 qt 对象。(download_webm 和播放器)
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
DownloadWebm *download_webm;
MyThread *DownloadWebm_Thread = new MyThread(download_webm);
DownloadWebm_Thread->start();
LinuWebmPlayer *player = new LinuWebmPlayer(argv[1],0);
QObject::connect(download_webm,SIGNAL(send_packege(Video_Bytes_Package)),player,SLOT(play()));
player->show();
return app.exec();
}
MyThread 头文件:
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <qthread.h>
#include <downloadwebm.h>
class MyThread : public QThread
{
Q_OBJECT
public:
MyThread(DownloadWebm *&we);
MyThread();
DownloadWebm **getWebm() const;
protected:
DownloadWebm **webm;
void run();
};
#endif // MYTHREAD_H
和 cpp:
#include "mythread.h"
MyThread::MyThread()
{
}
DownloadWebm **MyThread::getWebm() const
{
return webm;
}
MyThread::MyThread(DownloadWebm *&we)
{
webm = &we;
}
void MyThread::run()
{
*webm = new DownloadWebm("http://trilulilu.de.de/recstreamingsource?movie=3860","asd");
}
如果我从 main 注释 QObject::connect 行,一切正常,关于 qt 中线程之间的通信,我是否遗漏了什么?
................................................ .........