I want to connect two object(player and DownloadWebm) using slots and signals, but something strange happens. Here is my code :
LogInWindow *log_in=new LogInWindow(cstr,centerX,centerY,start_byte,end_byte);
QWidget::connect(log_in,SIGNAL(editingFinished()),&loop,SLOT(quit()));
loop.exec();//stop executing bellow code till user input a movie id
DownloadWebm *download_webm=nullptr;//download_webm is initialized in myThread constructor
MyThread *DownloadWebm_Thread = new MyThread(download_webm,cstr,start_byte,end_byte);
DownloadWebm_Thread->start();//start the thread
LinuxWebmPlayer *player = new LinuxWebmPlayer("video.webm",0);
while(download_webm == nullptr){}//wait till download_webm is initialized
qRegisterMetaType<Video_Bytes_Package>("Video_Bytes_Package");
qRegisterMetaType<Info>("Info");
QObject::connect(download_webm,SIGNAL(send_video_info(Info)),player,SLOT(set_video_info(Info)));
QObject::connect(download_webm,SIGNAL(send_packege(Video_Bytes_Package)),player,SLOT(add_packeges(Video_Bytes_Package)));
QObject::connect(download_webm,SIGNAL(send_finish_downloading(bool)),player,SLOT(video_is_commplet()));
QObject::connect(download_webm,SIGNAL(send_one_cluster_recived()),player,SLOT(calculate_frames()));
const bool connected = QObject::connect(player,SIGNAL(yes()),download_webm,SLOT(slot()));
emit player->yes();
qDebug() << "Connection established?" << connected;//return true
Q_ASSERT(connected);
When I connect download_webm to the player the slot receives the signal emitted from the download_webm but when I try to connect the player to download_webm, the connection is successful, the signal is emitted but the slot from download_webm is never called.
- DownloadWebm is running in another thread.
Here is my declaration of signal in downloadwebm :
class DownloadWebm : public QObject
{
Q_OBJECT
public:
DownloadWebm();
DownloadWebm(char *link,const char *app_path,long x,long y);
void start();
public slots:
void slot();
void first_package_analyzed(int,long);
private:
................
................
signals:
void send_packege(Video_Bytes_Package package);
void send_video_info(Info info);
void send_finish_downloading(bool) ;
And player header :
class LinuxWebmPlayer : public QMainWindow
{
Q_OBJECT
public:
LinuxWebmPlayer(char* argv,int pos);
signals:
void send_cluster_size_frames(long);
void yes();
public slots:
void add_packeges(Video_Bytes_Package);
void set_video_info(Info);