i dont understand why are my signals not working in this multi threaded app
file.h:
#include <QObject>
class FThread;
{
Q_OBJECT
public:
FThread *fthread;
public slots:
void print();
};
#include <QObject>
class FThread;
class File : public QObject
{
Q_OBJECT
public:
File(QObject *parent = 0);
FThread *fthread;
public slots:
void print();
};
To copy to clipboard, switch view to plain text mode
fthread.h
#include <QThread>
class File;
{
Q_OBJECT
public:
virtual void run();
File *f;
void sampleFunc();
signals:
void done();
};
#include <QThread>
class File;
class FThread : public QThread
{
Q_OBJECT
public:
FThread(QObject *parent = 0);
virtual void run();
File *f;
void sampleFunc();
signals:
void done();
};
To copy to clipboard, switch view to plain text mode
file.cpp:
#include "file.h"
#include <QDebug>
#include "fthread.h"
{
connect(fthread,SIGNAL(done()),this,SLOT(print()));
}
void File::print(){
qDebug()<<"printing from File object";
fthread.exit();
}
#include "file.h"
#include <QDebug>
#include "fthread.h"
File::File(QObject *parent) :
QObject(parent)
{
connect(fthread,SIGNAL(done()),this,SLOT(print()));
}
void File::print(){
qDebug()<<"printing from File object";
fthread.exit();
}
To copy to clipboard, switch view to plain text mode
fthread.cpp
#include "fthread.h"
#include "file.h"
#include <QDebug>
FThread
::FThread(QObject *parent
) :{
f=new File();
}
void FThread::run(){
sampleFunc();
this->exec();
}
void FThread::sampleFunc()
{
emit done(); //<<--------------SIGNAL SHOULD BE EMITTED FROM HERE
}
#include "fthread.h"
#include "file.h"
#include <QDebug>
FThread::FThread(QObject *parent) :
QThread(parent)
{
f=new File();
}
void FThread::run(){
sampleFunc();
this->exec();
}
void FThread::sampleFunc()
{
emit done(); //<<--------------SIGNAL SHOULD BE EMITTED FROM HERE
}
To copy to clipboard, switch view to plain text mode
main.cpp:
#include <QtCore/QCoreApplication>
#include <QDebug>
#include "fthread.h"
int main(int argc, char *argv[])
{
qDebug()<<"App started";
FThread fthread;
fthread.start();
fthread.wait();
return a.exec();
}
#include <QtCore/QCoreApplication>
#include <QDebug>
#include "fthread.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug()<<"App started";
FThread fthread;
fthread.start();
fthread.wait();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
NOTE:
i get following output:
App started
The program has unexpectedly finished.
...path/Thread exited with code 0
means it is exiting without error
any help please!!!!!!!
Bookmarks