void MainWindow::on_tb_prev_Refresh_clicked()
{
vFilePrev = new videoFilePreview();
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";
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";
}
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";
}
To copy to clipboard, switch view to plain text mode
#include <QObject>
#include <QDebug>
#include <QStringList>
class videoFilePreview
: public QObject{
Q_OBJECT
public:
explicit videoFilePreview
(QObject *parent
= 0);
private:
signals:
void finishedJob();
public slots:
};
#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:
};
To copy to clipboard, switch view to plain text mode
videoFilePreview
::videoFilePreview(QObject *parent
) :{
}
void videoFilePreview
::makePreview( QStringList fileList
) {
qDebug() << "in the thread: " << this->thread();
emit finishedJob();
}
videoFilePreview::videoFilePreview(QObject *parent) :
QObject(parent)
{
}
void videoFilePreview::makePreview( QStringList fileList )
{
qDebug() << "in the thread: " << this->thread();
emit finishedJob();
}
To copy to clipboard, switch view to plain text mode
And the problem with this is that connect( th, SIGNAL(finished()), this, SLOT(threadFinished())); never invoke SLOT(threadFinished());
Bookmarks