Halfpint
Halfpint

Reputation: 4079

Qt : reference to non-static member function must be called

I am new to Qt, and today I've been trying to adapt my application to work with QFuture to concurrently run some tasks off the main thread.

I have a method which changes the saturation value of a QImage which returns a QPixmap object to be drawn to my QGraphicsView. This all worked fine not using threads, but obviously it is extremely intensive on the main thread so I wanted to move it off.

I read a few articles regarding Threading in Qt, and found that v5 supports a concurrent run functionality, this sounded perfect for my use case as I thought I would just be able to dispatch my functions onto a new thread as in the snippet below:

void MainWindow::on_slideSaturation_valueChanged(int value)
{
    QFuture<QPixmap> future = QtConcurrent::run(slider->modifySaturation, value, image);
    future.waitForFinished();
    image = future.result();
    renderImageToCanvas();
    modified = true;
}

However I get the error reference to non-static member function must be called. This error is being called from my Sliders class, I know I haven't declared the method as static, but when I do it causes a whole heap of errors - is there any way I can pass this method to my concurrent call without it being declared as static?

Sliders.h

class Sliders
{    
public:
   Sliders();

   enum Member { RED, GREEN, BLUE, BRIGHTNESS, CONTRAST, HUE, SATURATION, LIGHTNESS };

   QPixmap modifySaturation(int, QPixmap);
   void setMember(enum Member, int);
   int getMember(enum Member);

private:
    int m_redValue;
    int m_greenValue;
    int m_blueValue;
    int m_brightnessValue;
    int m_contrastValue;
    int m_hueValue;
    int m_saturationValue;
    int m_lightnessValue;
};

Upvotes: 0

Views: 4038

Answers (1)

hank
hank

Reputation: 9853

You should call QtConcurrent::run like this:

QFuture<QPixmap> future = QtConcurrent::run(slider, 
                                            &Sliders::modifySaturation,  
                                            value, image);

But I think you are using it wrong anyway. Your on_slideSaturation_valueChanged slot, which I assume to be executed in the main thread, will be blocked until future.waitForFinished() returns.

Upvotes: 1

Related Questions