Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Properly changing the displayed chart in a QChartView
QtWS25 Last Chance

Properly changing the displayed chart in a QChartView

Scheduled Pinned Locked Moved Unsolved General and Desktop
qchartqchartviewpointers
4 Posts 3 Posters 754 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.
  • B Offline
    B Offline
    BradDev20
    wrote on 22 Apr 2022, 05:15 last edited by
    #1

    I am trying to change the displayed chart in a QChartView, but each time the program fails in some form.

    void MainWindow::updateRollResult(QString rollResult, QChart* chart){
    
        ui->rollResultLabel->setText("Sum of all dice rolls: " + rollResult);
        ui->diceChart = new QChartView(chart);
        ui->diceChart->repaint();
    }
    

    This code causes the QChartView to display nothing. However, I have tried things such as deleting the current chart given certain conditions, or setting the chartView's chart to a different chart, but those cause the program to crash after one or two operations. Why might this happen, and how do I correctly change the graph?

    A 1 Reply Last reply 22 Apr 2022, 06:05
    0
    • B BradDev20
      22 Apr 2022, 05:15

      I am trying to change the displayed chart in a QChartView, but each time the program fails in some form.

      void MainWindow::updateRollResult(QString rollResult, QChart* chart){
      
          ui->rollResultLabel->setText("Sum of all dice rolls: " + rollResult);
          ui->diceChart = new QChartView(chart);
          ui->diceChart->repaint();
      }
      

      This code causes the QChartView to display nothing. However, I have tried things such as deleting the current chart given certain conditions, or setting the chartView's chart to a different chart, but those cause the program to crash after one or two operations. Why might this happen, and how do I correctly change the graph?

      A Offline
      A Offline
      A.A.SEZEN
      wrote on 22 Apr 2022, 06:05 last edited by
      #2

      @BradDev20 said in Properly changing the displayed chart in a QChartView:

      ui->diceChart = new QChartView(chart);

      Are you sure you do it here?

      B 1 Reply Last reply 22 Apr 2022, 16:25
      0
      • A A.A.SEZEN
        22 Apr 2022, 06:05

        @BradDev20 said in Properly changing the displayed chart in a QChartView:

        ui->diceChart = new QChartView(chart);

        Are you sure you do it here?

        B Offline
        B Offline
        BradDev20
        wrote on 22 Apr 2022, 16:25 last edited by
        #3

        @A-A-SEZEN I have tried, but for some reason I just get a blank chart, even though I can confirm that the chart is being properly created.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 22 Apr 2022, 19:29 last edited by
          #4

          Hi,

          Why not use QChartView::setChart ?

          What you currently do is just replacing the object pointed by ui->diceView by a different one, but that is all.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          2/4

          22 Apr 2022, 06:05

          • Login

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