Hi all,
Application couldn't receive signal from QThread object.
I have implemented this way:
workerthread.h:
----------------------
#ifndef WORKERTHREAD_H
#define WORKERTHREAD_H
#include <QThread>
class workerthread
: public QThread{
Q_OBJECT
public:
explicit workerthread
(QObject *parent
= 0);
void run();
signals:
void signal_worker_thread();
};
#endif // WORKERTHREAD_H
#ifndef WORKERTHREAD_H
#define WORKERTHREAD_H
#include <QThread>
class workerthread : public QThread
{
Q_OBJECT
public:
explicit workerthread(QObject *parent = 0);
void run();
signals:
void signal_worker_thread();
};
#endif // WORKERTHREAD_H
To copy to clipboard, switch view to plain text mode
workerthread.cpp
-------------------------
#include "workerthread.h"
#include <QDebug>
workerthread
::workerthread(QObject *parent
) :{
}
void workerthread::run()
{
for(int i = 0; i < 10; ++ i)
{
qDebug() << "workerthread::signal_worker_thread()";
emit signal_worker_thread();
}
return;
}
#include "workerthread.h"
#include <QDebug>
workerthread::workerthread(QObject *parent) :
QThread(parent)
{
}
void workerthread::run()
{
for(int i = 0; i < 10; ++ i)
{
qDebug() << "workerthread::signal_worker_thread()";
emit signal_worker_thread();
}
return;
}
To copy to clipboard, switch view to plain text mode
WorkerThread is derived from QThread and overridden Run() method.
I have launched this thread on GUI - button click event to do background process.
Button click slot event:
---------------------------------
void ProductNameDialog::slotButtonClicked()//
{
workerthread *pthread = new workerthread();
QObject::connect(pthread,
SIGNAL(signal_worker_thread
()),
this,
SLOT(slotTest
()));
pthread->start();
pthread->wait();
accept();
return;
}
void ProductNameDialog::slotButtonClicked()//
{
workerthread *pthread = new workerthread();
QObject::connect(pthread, SIGNAL(signal_worker_thread()), this, SLOT(slotTest()));
pthread->start();
pthread->wait();
accept();
return;
}
To copy to clipboard, switch view to plain text mode
I have tested with sample Qt-GUI MainWindow application. It's working fine.
When I integrated into my application, slotTest() is not fired. I hope, I am missing something. Can somebody suggest me what I am missing here.
Thanks in advance.
Bookmarks