I want to connect two qt object that runs in different threads.(download_webm and player)
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 header file:
#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
and 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");
}
If I comment the QObject:: connect line from the main everything works fine, is there something I miss regarding communication between threads in qt?
......................................................
The problem is with download_webm the program sees the pointer as uninitialized so I think, but I initialized in the mythread constructor
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.