here is the simple code I am sharing. After running this..gives me
<warning: Exception at 0×754c812f, code: 0×406d1388: Startup complete, flags=0×0 (first chance)>
main.cpp
=======-
#include "SafeThreadDesign.h"
#include <QApplication>
#include <QThread>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
SafeThreadDesign w;
qDebug()<<"Inside main : thread Id is :"<<QThread::currentThreadId();
w.show();
return a.exec();
}
SafeThreadDesign.cpp
=================
#include "SafeThreadDesign.h"
#include "ui_SafeThreadDesign.h"
#include "QThread"
#include "Worker.h"
#include <QDebug>
SafeThreadDesign::SafeThreadDesign(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::SafeThreadDesign)
{
ui->setupUi(this);
qDebug()<<"Inside constructor SafeThreadDesign : thread Id is :"<<QThread::currentThreadId();
startNewThread();
}
SafeThreadDesign::~SafeThreadDesign()
{
delete ui;
}
void SafeThreadDesign::startNewThread()
{
qDebug()<<"Inside SafeThreadDesign::startNewThread() : thread Id is :"<<QThread::currentThreadId();
t = new QThread( this );
workerObj = new Worker( );
workerObj->moveToThread( t );
connect( t,SIGNAL(started()),workerObj,SLOT( startNewThread()), Qt::DirectConnection );
//connect( workerObj,SIGNAL(fnshd()),t,SLOT(quit()) );
t->start();
}
SafeThreadDesign.h
===================--
#include <QMainWindow>
#include <QThread>
#include <Worker.h>
namespace Ui {
class SafeThreadDesign;
}
class SafeThreadDesign : public QMainWindow
{
Q_OBJECT
public:
explicit SafeThreadDesign(QWidget *parent = 0);
~SafeThreadDesign();
private:
Ui::SafeThreadDesign *ui;
private slots:
void startNewThread();
public:
QThread* t;
Worker* workerObj;
};
worker.cpp
======
#include "Worker.h"
#include <QDebug>
#include <QThread>
Worker::Worker()
{
}
void Worker::startNewThread()
{
qDebug()<<"Inside starting : thread Id is :"<<QThread::currentThreadId();
}
worker.h
=======
#include <QObject>
class Worker : public QObject
{
Q_OBJECT
public:
Worker();
private slots:
void startNewThread();
};
=================
Where is the problem?Please need help
↧