I cannot do anything with my plot...
Your problem is that you have written your code in a way that gives you no ability to access your ChartView. You use a plain QMainWindow as the main window for your app and create your ChartView in main() where the pointer is not exposed to anything else.
Derive your own MainWindow class from QMainWindow. In the constructor for that class, create your ChartView, save the pointer to a member variable of the MainWindow class, and add it as the central widget:
// MainWindow.h
#include <QMainWindow>
#include <ChartView.h> // or whatever the name of the file is
{
Q_OBJECT
public:
MainWindow
( QWidget * parent
= 0 );
private:
ChartView * pChartView;
}
// MainWindow.cpp
#include "MainWindow.h"
MainWindow
::MainWindow( QWidget * parent
){
pChartView = new ChartView();
setCentralWidget( pChartView );
resize( 400, 300 );
}
// main.cpp
int main(int argc, char *argv[])
{
MainWindow window;
window.show();
return a.exec();
}
// MainWindow.h
#include <QMainWindow>
#include <ChartView.h> // or whatever the name of the file is
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget * parent = 0 );
private:
ChartView * pChartView;
}
// MainWindow.cpp
#include "MainWindow.h"
MainWindow::MainWindow( QWidget * parent )
: QMainWindow( parent )
{
pChartView = new ChartView();
setCentralWidget( pChartView );
resize( 400, 300 );
}
// main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow window;
window.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Now you have a pointer to your ChartView inside your MainWindow instance, so you can do whatever you want to change the plot or update its data.
Bookmarks