Signals&Slots Error: No matching function for call to 'connect' (requires 3 arguments, but 4 were provided)
-
Hello,
I am trying the following:
I have a .ui form and I want to make a Plot with QCustomPlot in one widget on this form. But I do not want to write the code that is necassary in the mainwindow.cpp but creating a new class, setting up the diagramm there and call this method from my mainwindow.cpp file, like this:
/*PlotterModel.cpp*/ #include "PlotterModel.h" #include "ui_PlotterView.h" PlotterModel::PlotterModel() { } void PlotterModel::setUpPlot(QCustomPlot *customPlotWidget) { customPlotWidget->addGraph(); // blue line customPlotWidget->graph(0)->setPen(QPen(QColor(40, 110, 255))); customPlotWidget->addGraph(); // red line customPlotWidget->graph(1)->setPen(QPen(QColor(255, 110, 40))); QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime); timeTicker->setTimeFormat("%h:%m:%s"); customPlot->xAxis->setTicker(timeTicker); customPlot->axisRect()->setupFullAxesBox(); customPlot->yAxis->setRange(-1.2, 1.2); // make left and bottom axes transfer their ranges to right and top axes: connect(customPlotWidget->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlotWidget->xAxis2, SLOT(setRange(QCPRange))); connect(customPlotWidget->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlotWidget->yAxis2, SLOT(setRange(QCPRange))); // setup a timer that repeatedly calls MainWindow::realtimeDataSlot: connect(dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot())); dataTimer->start(0); // Interval 0 means to refresh as fast as possible }
here is my header file for this class
/*PlotterModel.h*/ #ifndef PLOTTERMODEL_H #define PLOTTERMODEL_H #include <qcustomplot.h> #include <QTimer> class PlotterModel { Q_OBJECT public: PlotterModel(); void setUpAccelerationDiagram(QCustomPlot *customPlotWidget); QTimer *dataTimer = new QTimer(); }; #endif // PLOTTERMODEL_H
So, now I want to call the above defined method
setupPlot()
and the parameter is my widget in my .ui file which I promotet to QCustomPlot as in the basic tutorial. So how can I call this method from my mainwindow.cpp file, can I callui->customPlotWidget->replot()
from my mainwindow.cpp? Because all my connect statements from my methodsetupPlot()
give me the error:PlotterModel.cpp:29:5: error: no matching function for call to 'connect' winsock.h:751:16: note: candidate function not viable: requires 3 arguments, but 4 were provided
-
Since PlotterModel is not derived from QObject there is also no function QObject::connect() which could be called. So it's using another connect function from winsock.h which does not match.
--> you forgot to derive from QObject (although you already added Q_OBJECT which should trigger a warning). -
@TUStudi said in Signals&Slots Error: No matching function for call to 'connect' (requires 3 arguments, but 4 were provided):
So how can I call this method from my mainwindow.cpp file
In MainWindow.cpp
PlotterModel *pM = new PlotterModel(); pM->setupPlot( ui->yourCustomPlotWidget );
or use a connection to setup your PlotterModel on mainWindow initialization.