I am migrating a project from Qt 4.x to 5, and there is a class that contains an attribute that goes:
Qt::PenStyle penStyle;
and its respective get function:
Qt::PenStyle getPenStyle() {return penStyle;}
I get a compilation error saying that
error: 'QVariant::QVariant(Qt::PenStyle)' is private
QVariant(Qt::PenStyle) Q_DECL_EQ_DELETE;
^
..\marssies\painterbar.cpp:217:88: error: within this context
lineStyle -> setCurrentIndex(lineStyle -> findData(graphicObject->getPenStyle()));
^
Doing some research I found this:
QVariant:
*Inconsistent constructor taking Qt::GlobalColor and producing QVariant(QColor) instance was removed. Code constructing such variants can be migrated by explicitly calling QColor constructor. For example from “QVariant(Qt::red)” to “QVariant(QColor(Qt::red))*Similarly, implicit creation of QVariants from enum values Qt::BrushStyle, Qt::PenStyle, and Qt::CursorShape have been removed. Create objects explicitly or use static_cast(Qt::SolidLine) to create a QVariant of type int with the same value as the enum.
The question is, how should I declare the attribute/function if I cant do Qt::PenStyle just like that? What does it mean by with creating objects explicitly? I've tried doing something like the quote says but I didnt manage to solve it. I did manage to solve other similar errors but none of them were declarations of attributes or functions.
Full error:
In file included from ..\..\..\..\..\Qt5\5.2.1\mingw48_32\include\QtCore/qsettings.h:46:0,
from ..\..\..\..\..\Qt5\5.2.1\mingw48_32\include\QtCore/QSettings:1,
from ..\marssies\appcommon.h:10,
from ..\marssies\painterbar.h:5,
from ..\marssies\painterbar.cpp:1:
..\..\..\..\..\Qt5\5.2.1\mingw48_32\include/QtCore/qvariant.h: In member function 'void PainterBar::setGraphicObject(GraphicsPrimitive*, PainterBar::FinishMode)':
..\..\..\..\..\Qt5\5.2.1\mingw48_32\include/QtCore/qvariant.h:482:5: error: 'QVariant::QVariant(Qt::PenStyle)' is private
QVariant(Qt::PenStyle) Q_DECL_EQ_DELETE;
^
..\marssies\painterbar.cpp:217:88: error: within this context
lineStyle -> setCurrentIndex(lineStyle -> findData(graphicObject->getPenStyle()));
^