Solved How do I inherit QChart from the main window?
-
How do I inherit QChart from the main window?
mainwindow.h
class MainWindow : public QMainWindow { public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); }
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {...}
I want to access QChart's protected member so I want to inherit QChart from main window.
I want to deal with QChart's viewportEvent, mousePressEvent, mouseMoveEvent.I made the correction as below.
mainwindow.h
class MainWindow : public QMainWindow, public QChart { public: MainWindow(QWidget *parent = nullptr, QChart *qc = nullptr); ~MainWindow();
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent, QChart *qc) : QMainWindow(parent), QChart(qc), ui(new Ui::MainWindow) {...}
But, I get an error.
"mainwindow parameter error" and Modifying parent->connect() and How can I access the parent in a function declared inside mainwidow?
For example, if I use setWindowTitle("text") , I cannot use parent->setWindowTitle().Thank you for reading my poor English.
-
@LISP you can't do that,
with the current implementation of the Q_OBJECT magic, you can not inherit multiple times from QObject.
If you really need to access protected stuff from QCharts, make an interface class around it and define getters and setters
-
@LISP you can't do that,
with the current implementation of the Q_OBJECT magic, you can not inherit multiple times from QObject.
If you really need to access protected stuff from QCharts, make an interface class around it and define getters and setters