简体   繁体   中英

Access QCustomPlot Variable

In Short:

I need to access a QCustomPlot variable in a WidgetClass. But I can't because it's private in that context. How is this accomplished?

What I have done:

I have a class that creates a graph and a widget class that calls the graph class My QCustomPlot variable is a private variable that is being declared in the graph class, but I need to access this variable in the Widget Class.

I have a generate_graphs slot that gets data and passes the data to the graph class and from there the graph is created. I am saving to a png, so I need to access the graph variable with this data, the variable is passed data in the WidgetClass which then calls the graph class, which generates the graph.

The graph class variable (in the Widget Class) is declared like so: GraphWidget* graph I try to access the QCustomPlot variable in that slot like this: graph->QCustomPlot->savePNG() I keep getting an error that says QCustomPlot* GraphWidget::QCustomPlot is private within this context

I then created a function to just return the GraphWidget* graph so I could access that variable in the graph class. Instead so I could access the QCustomPlot variable without it being private in that context. This caused errors because it needs to be passed a GraphWidget* graph which is not declared in the GraphWidget class.

This was an isolated problem, but if anyone else has a similar problem my suggestion is this:

Make sure that your GraphWidget variable (the variable to creates a QCustomPlot ) is accessible by the entire class that is trying to use it. I was trying to pass it a bunch of different ways, and none of them were correct.

Also make sure you create a public function in the GraphWidget class in order to access the savePng() function that QCustomPlot uses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM