Glep Fingerman
Glep Fingerman

Reputation: 41

Using Enums in Qt slots

In the class QCustomPlot have enums that I want to use in the constructor of the QWidget class, which uses class QCustomPlot.

#include "qcustomplot.h"

SignalViewerDialog::SignalViewerDialog(QVector<double> x_1,
                                       QVector<double> y_1,
                                       QCPScatterStyle::ScatterProperty ScatterProp,
                                       QCPScatterStyle::ScatterShape ScatterShp,
                                       QCPGraph::LineStyle LineSt,
                                       QWidget *parent) : QDialog(parent)

ERROR

/Users/konstantin/Desktop/SVMGLEP/signalviewerdialog.cpp:72: ошибка: reference to type 'const QCPScatterStyle' could not bind to an lvalue of type 'QCPScatterStyle::ScatterProperty' ui.widgetGraph->graph()->setScatterStyle(ScatterProp); ^~~~~~~~~~~

Upvotes: 1

Views: 224

Answers (1)

iksemyonov
iksemyonov

Reputation: 4196

This has nothing to with the problem of passing enums in signal-slot connection, where you need to register the enum within the Qt metatype system. This is a simple type mismatch in plain C++.

To quote the reference:

Specifying a scatter style

You can set all these configurations either by calling the respective functions on an instance:

QCPScatterStyle myScatter;  
myScatter.setShape(QCPScatterStyle::ssCircle);  
myScatter.setPen(QPen(Qt::blue));   myScatter.setBrush(Qt::white);  
myScatter.setSize(5);  
customPlot->graph(0)->setScatterStyle(myScatter);

Or you can use one of the various constructors that take different parameter combinations, making it easy to specify a scatter style in a single call, like so:

customPlot->graph(0)->setScatterStyle(
   QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::blue, Qt::white, 5)
);

You are passing an enum of type QCPScatterStyle::ScatterProperty in place of an object of class QCPScatterStyle.

Edit 1: Hence, you need to use

ui.widgetGraph->graph()->setScatterStyle(QCPScatterStyle(ScatterProp));

Edit 2: Also I'd like to note that you're using CamelCase for the names of the function parameters of type enum. Maybe you're doing that because they are enums, but I'd advise againt doing that, since later on in the code they appear to be actual enum values, not variable names.

Upvotes: 1

Related Questions