dpn
15th September 2013, 16:36
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
workerthread.cpp
-------------------------
#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;
}
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;
}
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.
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
workerthread.cpp
-------------------------
#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;
}
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;
}
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.