Hello!
I have a static class that is called upon by other classes to do some processing. I want this function to be static AND in its own thread, so the program doesnt hang when entering the function.
Now, I read the Qt doc and decided to use QtConcurrent::run, but I get a linker error.
Here is my code:
ImageProcessor.cpp file
#include "CustomEvent"
#include <QtConcurrentRun>
#include <QFuture>
#include "ImageProcessor.h"
#include <QSharedPointer>
#include <queue>
QSharedPointer<CustomEvent> ImageProcessor
::Process(QObject *asker, std
::queue<Image> images
){
extern QSharedPointer<CustomEvent> Calculate
(QObject, std
::queue<Image>
);
QFuture<QSharedPointer<CustomEvent>> future = QtConcurrent::run(Calculate, asker, images);
future.waitForFinished();
return future.result();
}
QSharedPointer<CustomEvent> Calculate
(QObject *asker, std
::queue<Image> images
){
cv::Mat scaleMap;
Image AdditionImage(images.front());
images.pop();
//Dummy while function
while (images.size() != 0)
{
AdditionImage += images.front();
images.pop();
}
CustomEvent *processedImage = new CustomEvent(asker, scaleMap);
QSharedPointer<CustomEvent> processedImageSharedPointer(processedImage);
return processedImageSharedPointer;
}
ImageProcessor.cpp file
#include "CustomEvent"
#include <QtConcurrentRun>
#include <QFuture>
#include "ImageProcessor.h"
#include <QSharedPointer>
#include <queue>
QSharedPointer<CustomEvent> ImageProcessor::Process(QObject *asker, std::queue<Image> images)
{
QMutexLocker locker(m_mutex);
extern QSharedPointer<CustomEvent> Calculate(QObject, std::queue<Image>);
QFuture<QSharedPointer<CustomEvent>> future = QtConcurrent::run(Calculate, asker, images);
future.waitForFinished();
return future.result();
}
QSharedPointer<CustomEvent> Calculate(QObject *asker, std::queue<Image> images)
{
cv::Mat scaleMap;
Image AdditionImage(images.front());
images.pop();
//Dummy while function
while (images.size() != 0)
{
AdditionImage += images.front();
images.pop();
}
CustomEvent *processedImage = new CustomEvent(asker, scaleMap);
QSharedPointer<CustomEvent> processedImageSharedPointer(processedImage);
return processedImageSharedPointer;
}
To copy to clipboard, switch view to plain text mode
Linker error: Unresolved external symbol in class QSharedPointer<CustomEvent> in class Calculate(...)
From what I get the extern function does not have access to the inclusions I added at the top of the cpp file?
Can someone point me to where my error is? Or if there is a better way to code this?
Thank you!
Bookmarks