PDA

View Full Version : Static class threading problem



WSQtProgrammer
3rd August 2012, 18:55
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)
{
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;
}



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!

amleto
3rd August 2012, 22:42
You define

extern QSharedPointer<CustomEvent> Calculate(QObject, std::queue<Image>);

Why did you use extern? Do you know what it is for?

Why does it have a different signature to the implementation that you define below,
QSharedPointer<CustomEvent> Calculate(QObject*, std::queue<Image>);
?