Talei
28th July 2010, 07:10
Hello,
I wrote a single piece of code that need to be run in the thread, but I have problem quit'ing the QThread itself.
void MainWindow::on_tb_prev_Refresh_clicked()
{
vFilePrev = new videoFilePreview();
th = new QThread();
vFilePrev->moveToThread( th );
connect( th, SIGNAL(started()), this, SLOT(threadStarted()));
connect( th, SIGNAL(finished()), this, SLOT(threadFinished()));
connect(vFilePrev, SIGNAL(finishedJob()), this, SLOT( vidPreviewFinished()));
connect(vFilePrev, SIGNAL(finishedJob()), th, SLOT( quit()));
th->start();
qDebug() << "gui thread: " << this->thread();
}
void MainWindow::threadStarted()
{
qDebug() << "Start th";
QStringList tmp;
vFilePrev->makePreview( tmp );
}
void MainWindow::vidPreviewFinished()
{
qDebug() << "vidPreviewFinished in thread: " << this->thread();
disconnect(vFilePrev, SIGNAL(finishedJob()), this, SLOT( vidPreviewFinished()));
delete vFilePrev;
}
void MainWindow::threadFinished()
{
disconnect( th, SIGNAL(started()), this, SLOT(threadStarted()));
disconnect( th, SIGNAL(finished()), this, SLOT(threadFinished()));
disconnect( vFilePrev, SIGNAL(finishedJob()), th, SLOT( quit()));
delete th;
qDebug() << "delete th";
}
#include <QObject>
#include <QDebug>
#include <QStringList>
class videoFilePreview : public QObject
{
Q_OBJECT
public:
explicit videoFilePreview(QObject *parent = 0);
void makePreview( QStringList );
private:
signals:
void finishedJob();
public slots:
};
videoFilePreview::videoFilePreview(QObject *parent) :
QObject(parent)
{
}
void videoFilePreview::makePreview( QStringList fileList )
{
qDebug() << "in the thread: " << this->thread();
emit finishedJob();
}
And the problem with this is that connect( th, SIGNAL(finished()), this, SLOT(threadFinished())); never invoke SLOT(threadFinished());
Thanks for any suggestions.
Regards
I wrote a single piece of code that need to be run in the thread, but I have problem quit'ing the QThread itself.
void MainWindow::on_tb_prev_Refresh_clicked()
{
vFilePrev = new videoFilePreview();
th = new QThread();
vFilePrev->moveToThread( th );
connect( th, SIGNAL(started()), this, SLOT(threadStarted()));
connect( th, SIGNAL(finished()), this, SLOT(threadFinished()));
connect(vFilePrev, SIGNAL(finishedJob()), this, SLOT( vidPreviewFinished()));
connect(vFilePrev, SIGNAL(finishedJob()), th, SLOT( quit()));
th->start();
qDebug() << "gui thread: " << this->thread();
}
void MainWindow::threadStarted()
{
qDebug() << "Start th";
QStringList tmp;
vFilePrev->makePreview( tmp );
}
void MainWindow::vidPreviewFinished()
{
qDebug() << "vidPreviewFinished in thread: " << this->thread();
disconnect(vFilePrev, SIGNAL(finishedJob()), this, SLOT( vidPreviewFinished()));
delete vFilePrev;
}
void MainWindow::threadFinished()
{
disconnect( th, SIGNAL(started()), this, SLOT(threadStarted()));
disconnect( th, SIGNAL(finished()), this, SLOT(threadFinished()));
disconnect( vFilePrev, SIGNAL(finishedJob()), th, SLOT( quit()));
delete th;
qDebug() << "delete th";
}
#include <QObject>
#include <QDebug>
#include <QStringList>
class videoFilePreview : public QObject
{
Q_OBJECT
public:
explicit videoFilePreview(QObject *parent = 0);
void makePreview( QStringList );
private:
signals:
void finishedJob();
public slots:
};
videoFilePreview::videoFilePreview(QObject *parent) :
QObject(parent)
{
}
void videoFilePreview::makePreview( QStringList fileList )
{
qDebug() << "in the thread: " << this->thread();
emit finishedJob();
}
And the problem with this is that connect( th, SIGNAL(finished()), this, SLOT(threadFinished())); never invoke SLOT(threadFinished());
Thanks for any suggestions.
Regards