Hi,
#include <QThread>
{
Q_OBJECT
public:
//Redefine this method with your computation
void run()
{
while(!bStop)
{
//Do some work
emit
(emitShowText
(QString("Hello Thread"));
...
}
}
signals:
void emitShowText
(QString);
//Define all the signals you want to emit void emitShowProcessProgress(int);
}
#include <QThread>
class myThread : public QThread
{
Q_OBJECT
public:
//Redefine this method with your computation
void run()
{
while(!bStop)
{
//Do some work
emit (emitShowText(QString("Hello Thread"));
...
}
}
signals:
void emitShowText(QString); //Define all the signals you want to emit
void emitShowProcessProgress(int);
}
To copy to clipboard, switch view to plain text mode
{
ui.setupUi(this); //Setup UI if used a GUI editor like QDesigner
//Create the thread and connect it's signals to "this" slots
m_pThread = new myThread(this);
bool bC
= connect(m_pThread,
SIGNAL(emitShowText
(QString)),
this,
SLOT(showText
(QString)),Qt
::QueuedConnection);
//Insert a debug point and take a look at console out. If connection fail it will reach error message on it
m_pThread->start(); //Enter the Thread "run" method
}
myAppWindow::myAppWindow(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
{
ui.setupUi(this); //Setup UI if used a GUI editor like QDesigner
//Create the thread and connect it's signals to "this" slots
m_pThread = new myThread(this);
bool bC = connect(m_pThread,SIGNAL(emitShowText(QString)),this,SLOT(showText(QString)),Qt::QueuedConnection); //Insert a debug point and take a look at console out. If connection fail it will reach error message on it
m_pThread->start(); //Enter the Thread "run" method
}
To copy to clipboard, switch view to plain text mode
Bookmarks