Problem with function "setCentralWidget"
-
Hi,
I wrote some clas named "Monitor":
monitor.h
class Monitor : public QGridLayout { Q_OBJECT public: Monitor(QWidget *parent = 0); public slots: void setValue(float value); };monitor.cpp
Monitor::Monitor(QWidget *parent) :QGridLayout(parent) { }But when I try seet this widet in mainwindow with "setCentralWidget()" method I got some error:
Monitor *monitor = new Monitor(this); setCentralWidget(monitor);Error:
error: no matching function for call to 'MainWindow::setCentralWidget(Monitor*&)' no known conversion for argument 1 from 'Monitor*' to 'QWidget*'How colud I fix that?
-
Hi,
I wrote some clas named "Monitor":
monitor.h
class Monitor : public QGridLayout { Q_OBJECT public: Monitor(QWidget *parent = 0); public slots: void setValue(float value); };monitor.cpp
Monitor::Monitor(QWidget *parent) :QGridLayout(parent) { }But when I try seet this widet in mainwindow with "setCentralWidget()" method I got some error:
Monitor *monitor = new Monitor(this); setCentralWidget(monitor);Error:
error: no matching function for call to 'MainWindow::setCentralWidget(Monitor*&)' no known conversion for argument 1 from 'Monitor*' to 'QWidget*'How colud I fix that?
@Creatorczyk said in Problem with function "setCentralWidget":
class Monitor : public QGridLayoutBut when I try seet this widet
no known conversion for argument 1 from 'Monitor*' to 'QWidget*'As the error message tells you. Your
Monitoris aQLayoutnot aQWidget, so you can't callsetCentralWidget()on it, as the name suggests.You could set an empty
QWidgetonQMainWindow::setCentralWidget(), and then setMonitoras that widget's layout, if that is what you are wanting to do. But I am unconvinced as to what you are trying to do with yourMonitor: given that it is aQGridLayout, what is itssetValue()intended to do, layouts/grid layouts don't have "values"?