Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QtGraphs Bug

QtGraphs Bug

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qtgraphspyside6
5 Posts 2 Posters 184 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SpaceCool
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • S SpaceCool

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @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].

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • jsulmJ jsulm

        @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].

        S Offline
        S Offline
        SpaceCool
        wrote on last edited by
        #3

        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.

        jsulmJ 1 Reply Last reply
        0
        • S SpaceCool

          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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • jsulmJ jsulm

            @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.

            S Offline
            S Offline
            SpaceCool
            wrote on last edited by
            #5

            @jsulm

            @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.

            Снимок экрана 2025-04-11 094816.png

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved