QtGraphs Bug
-
Hi all,
this is my first post to the forum so, first of all, "hello!" to everyone. Secondly, I would apologize for my English.
Since I'm a student, I became interested in QtGraphs for plotting graphs, so I decided to test it. Everything was fine while I was working inside qml.
But when I tried to dynamically add QSplineSeries from python, I ran into the problem that when adding a second point to such a series from python, the application closes. I assume this is a bug, but I admit the possibility that I did not understand the topic well, so if anyone has any thoughts on how to solve this problem, I will be glad to take a look.Here are some pieces of my code:
#main.py class GraphController(QObject): def __init__(self): super().__init__() self._graph_view = None self.seriesList = [] @Slot('QVariant') def set_graph_view(self, graph_view): self._graph_view = graph_view @Slot(list) def set_seriesList (self, list): self.seriesList = list @Slot() def create_series (self): series = QSplineSeries(self) self._graph_view.addSeries(series) self.seriesList.append(series) @Slot() def add_point (self): self.seriesList[len(self.seriesList) - 1].append(random.random() * 10, random.random() * 10) #Reg controller = GraphController() engine.rootContext().setContextProperty("graphController", controller)
//Main.qml GraphsView { id: graph //... Component.onCompleted: { graphController.set_graph_view(graph) graphController.set_seriesList(graph.seriesList) } } Button { onClicked: { graphController.create_series() } Button { onClicked: { graphController.add_point() }
P.S. It should be clarified that if you add points to QSplineSeries created in qml and not python, all points are added.
Thanks to everyone who paid attention to this topic.
-
Hi all,
this is my first post to the forum so, first of all, "hello!" to everyone. Secondly, I would apologize for my English.
Since I'm a student, I became interested in QtGraphs for plotting graphs, so I decided to test it. Everything was fine while I was working inside qml.
But when I tried to dynamically add QSplineSeries from python, I ran into the problem that when adding a second point to such a series from python, the application closes. I assume this is a bug, but I admit the possibility that I did not understand the topic well, so if anyone has any thoughts on how to solve this problem, I will be glad to take a look.Here are some pieces of my code:
#main.py class GraphController(QObject): def __init__(self): super().__init__() self._graph_view = None self.seriesList = [] @Slot('QVariant') def set_graph_view(self, graph_view): self._graph_view = graph_view @Slot(list) def set_seriesList (self, list): self.seriesList = list @Slot() def create_series (self): series = QSplineSeries(self) self._graph_view.addSeries(series) self.seriesList.append(series) @Slot() def add_point (self): self.seriesList[len(self.seriesList) - 1].append(random.random() * 10, random.random() * 10) #Reg controller = GraphController() engine.rootContext().setContextProperty("graphController", controller)
//Main.qml GraphsView { id: graph //... Component.onCompleted: { graphController.set_graph_view(graph) graphController.set_seriesList(graph.seriesList) } } Button { onClicked: { graphController.create_series() } Button { onClicked: { graphController.add_point() }
P.S. It should be clarified that if you add points to QSplineSeries created in qml and not python, all points are added.
Thanks to everyone who paid attention to this topic.
@SpaceCool said in QtGraphs Bug:
I assume this is a bug
Before assuming a bug in a framework/lib you should make sure it is not your code. Most of the time the problem is in your code.
If the application crashes then the first thing to do is to run it in debugger to see where exactly it is crashing and how the stack trace looks like. And you did not even mention what kind of crash it is (what es the Python exception?).
Btw. in Python you can access last element in a list like this: self.seriesList[-1].
-
@SpaceCool said in QtGraphs Bug:
I assume this is a bug
Before assuming a bug in a framework/lib you should make sure it is not your code. Most of the time the problem is in your code.
If the application crashes then the first thing to do is to run it in debugger to see where exactly it is crashing and how the stack trace looks like. And you did not even mention what kind of crash it is (what es the Python exception?).
Btw. in Python you can access last element in a list like this: self.seriesList[-1].
Hello @jsulm,
I'm glad you noticed this topic.
@jsulm said in QtGraphs Bug:
run it in debugger
You're absolutely right, my mistake is that I didn't specify that I used the debugger as well. And the result was zero, that the qml debugger, that python in both VS Code and Qt Creator does not show anything, it just closes the window.
I'm ready to try the tests that the community will offer in this topic, but I've already tried everything I know, which is exactly why I wrote about this it.
By adding a button that outputs the last point of the series to the console
Button { onClicked: { console.log(graph.seriesList) var series = graph.seriesList[graph.seriesList.length - 1] console.log(series.at(-1)) }
And by clicking the buttons in this order: Create->Add Point->Output point to console->Add point. The console will have this:
qml: [QSplineSeries(0x2781e503f10),QSplineSeries(0x2781cac62b0)] qml: QPointF(4.94066e-324, 1.4822e-323)
@jsulm said in QtGraphs Bug:
Btw. in Python you can access last element in a list like this: self.seriesList[-1].
Thank you for reminding me about this opportunity.
-
Hello @jsulm,
I'm glad you noticed this topic.
@jsulm said in QtGraphs Bug:
run it in debugger
You're absolutely right, my mistake is that I didn't specify that I used the debugger as well. And the result was zero, that the qml debugger, that python in both VS Code and Qt Creator does not show anything, it just closes the window.
I'm ready to try the tests that the community will offer in this topic, but I've already tried everything I know, which is exactly why I wrote about this it.
By adding a button that outputs the last point of the series to the console
Button { onClicked: { console.log(graph.seriesList) var series = graph.seriesList[graph.seriesList.length - 1] console.log(series.at(-1)) }
And by clicking the buttons in this order: Create->Add Point->Output point to console->Add point. The console will have this:
qml: [QSplineSeries(0x2781e503f10),QSplineSeries(0x2781cac62b0)] qml: QPointF(4.94066e-324, 1.4822e-323)
@jsulm said in QtGraphs Bug:
Btw. in Python you can access last element in a list like this: self.seriesList[-1].
Thank you for reminding me about this opportunity.
@SpaceCool said in QtGraphs Bug:
qml: QPointF(4.94066e-324, 1.4822e-323)
Look at these numbers. I doubt this is what you added.
"that python in both VS Code and Qt Creator does not show anything, it just closes the window" - run the app in a terminal, then you should see the Python exception.
-
@SpaceCool said in QtGraphs Bug:
qml: QPointF(4.94066e-324, 1.4822e-323)
Look at these numbers. I doubt this is what you added.
"that python in both VS Code and Qt Creator does not show anything, it just closes the window" - run the app in a terminal, then you should see the Python exception.
@jsulm said in QtGraphs Bug:
Look at these numbers. I doubt this is what you added.
Yes, I agree the numbers are output strangely.
@jsulm said in QtGraphs Bug:
run the app in a terminal, then you should see the Python exception.
Perhaps I don't have enough knowledge, I would be glad if you could explain how a regular terminal differs from a terminal in VS Code. I don't understand what new things I'll be able to see. I also see python exceptions in the VS Code terminal, but they were not noticed in this code.
In any case, how can you explain that the same code works without problems when replacing QSplineSeries with QLineSeries, I attach a screenshot of an example of the work.