fallenshadow
February 26th, 2017, 11:46 PM
Hi all,
I'm trying to implement a filter worker to filter an image in a separate thread, then return the image afterwards. However, it doesn't work at the moment. Any ideas? Its hard to debug an issue without an actual error showing up.
filterworker.cpp
#include "filterworker.h"
#include "FilterManager.h"
#include "PaintWidget.h"
#include <QDebug>
FilterWorker::FilterWorker(QObject *parent) : QObject(parent)
{
}
void FilterWorker::setImage(QImage image)
{
currentImage = image;
}
void FilterWorker::process()
{
qDebug() << "test";
QImage newImage;
newImage = FilterManager::instance()->wave(currentImage);
emit fileProcessFinished(newImage);
}
filterworker.h
#ifndef FILTERWORKER_H
#define FILTERWORKER_H
#include <QObject>
#include "mainwindow.h"
class FilterWorker : public QObject
{
Q_OBJECT
public:
//FilterWorker();
explicit FilterWorker(QObject *parent = 0);
void setParent(MainWindow* parent){m_parent = parent;}
void setImage(QImage image);
public slots:
void process();
signals:
void fileProcessFinished(QImage image);
private:
MainWindow* m_parent;
QImage currentImage;
};
#endif // FILTERWORKER_H
mainwindow.cpp - on_image_filtered(QImage image)
void MainWindow::on_image_filtered(QImage image)
{
PaintWidget *widget = getCurrentPaintWidget();
if (widget)
widget->setImage(image);
}
mainwindow.cpp -on_actionSwirl_triggered()
QThread *thread = new QThread();
FilterWorker *worker = new FilterWorker();
PaintWidget *widget = getCurrentPaintWidget();
if(widget)
worker->setImage(widget->image());
worker->setParent(this);
worker->moveToThread(thread);
connect(thread, SIGNAL(started()), worker, SLOT(process()));
connect(worker, SIGNAL(fileProcessFinished(QImage)), this, SLOT(on_image_filtered(QImage)));
thread->start();
If you want to play around with the code you can take a fork here: https://github.com/PhotoFiltre-LX/photofiltrelx
I would gladly accept a contribution if someone can figure it out.
I'm trying to implement a filter worker to filter an image in a separate thread, then return the image afterwards. However, it doesn't work at the moment. Any ideas? Its hard to debug an issue without an actual error showing up.
filterworker.cpp
#include "filterworker.h"
#include "FilterManager.h"
#include "PaintWidget.h"
#include <QDebug>
FilterWorker::FilterWorker(QObject *parent) : QObject(parent)
{
}
void FilterWorker::setImage(QImage image)
{
currentImage = image;
}
void FilterWorker::process()
{
qDebug() << "test";
QImage newImage;
newImage = FilterManager::instance()->wave(currentImage);
emit fileProcessFinished(newImage);
}
filterworker.h
#ifndef FILTERWORKER_H
#define FILTERWORKER_H
#include <QObject>
#include "mainwindow.h"
class FilterWorker : public QObject
{
Q_OBJECT
public:
//FilterWorker();
explicit FilterWorker(QObject *parent = 0);
void setParent(MainWindow* parent){m_parent = parent;}
void setImage(QImage image);
public slots:
void process();
signals:
void fileProcessFinished(QImage image);
private:
MainWindow* m_parent;
QImage currentImage;
};
#endif // FILTERWORKER_H
mainwindow.cpp - on_image_filtered(QImage image)
void MainWindow::on_image_filtered(QImage image)
{
PaintWidget *widget = getCurrentPaintWidget();
if (widget)
widget->setImage(image);
}
mainwindow.cpp -on_actionSwirl_triggered()
QThread *thread = new QThread();
FilterWorker *worker = new FilterWorker();
PaintWidget *widget = getCurrentPaintWidget();
if(widget)
worker->setImage(widget->image());
worker->setParent(this);
worker->moveToThread(thread);
connect(thread, SIGNAL(started()), worker, SLOT(process()));
connect(worker, SIGNAL(fileProcessFinished(QImage)), this, SLOT(on_image_filtered(QImage)));
thread->start();
If you want to play around with the code you can take a fork here: https://github.com/PhotoFiltre-LX/photofiltrelx
I would gladly accept a contribution if someone can figure it out.