QMutexLocker, QMutex C2530 references must be initialized

Viewed 642

I have QMutex m_mutex; as a private field in my class and I try to lock it using QMutexLocker from one of the methods but when I try to build it I get C2530 error.(My compiler is MSVC 2015).

#include <QObject>
#include <QMutex>
#include <QMutexLocker>

class MyClass : public QObject
    Q_OBJECT
public:
    MyClass(QObject *parent = 0) : QObject(parent) {}

    void setValue(const SomeEnum& val) 
    {
        QMutexLocker(&m_mutex) // C2530
        m_enum = val;
    }
private:
    QMutex m_mutex;
    SomeEnum m_enum;
};

EDIT: it works when I use &this->m_mutex

1 Answers
Related