Hello, I'm working in Qt 5.7 (MSVC2015) and I'm having problems getting QChartView to display in my QHBoxLayout. I'm writing a program that will parse through a file and add up instances of Ford, Chevy or GMC trucks per a given location. I then want to graphically represent them via a pie chart. I'm trying to use QHPieModelMapper to dynamically update the pie chart upon reading other files. Here's what I have:
MainWindow.h
Qt Code:
  1. class MainWindow : public QMainWindow, private Ui::MainWindow
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. explicit MainWindow(QWidget *parent = 0);
  7. ~MainWindow();
  8.  
  9. private:
  10. void setupModel();
  11. void setupChart();
  12. void readFile();
  13. void updateCarTotals(const QString &, int FORDS=0, int CHEVYS=0,int GMCS=0);
  14. QChart *m_chart;
  15. QStandardItemModel *overallCarCountModel;
  16. int totalFord,totalChevy,totalGMC;
  17. };
To copy to clipboard, switch view to plain text mode 

MainWindow.cpp
Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
  2. {
  3. setupModel()
  4. setupChart()
  5. }
  6.  
  7. void MainWindow::setupModel()
  8. {
  9. overallCarCountModel = new QStandardItemModel(this);
  10. overallCarCountModel->insertRows(0,2);
  11. overallCarCountModel->insertColumns(0,3);
  12. overallCarCountModel->setHeaderData(0,Qt::Horizontal,"Ford");
  13. overallCarCountModel->setHeaderData(1,Qt::Horizontal,"Chevy");
  14. overallCarCountModel->setHeaderData(2,Qt::Horizontal,"GMC");
  15. }
  16.  
  17. void MainWindow::setupChart()
  18. {
  19. QHBoxLayout* chartLayout = new QHBoxLayout;
  20. m_chart = new QChart;
  21. m_chart->setTitle("Total Cars");
  22.  
  23. QPieSeries *series = new QPieSeries();
  24. QHPieModelMapper *pcMapper = new QHPieModelMapper(this);
  25. series->setPieSize(0.7); //I know this is the default, just trying whatever to get it working
  26. pcMapper->setValuesRow(0);
  27. pcMapper->setSeries(series);
  28. pcMapper->setModel(overallCarCountModel );
  29. m_chart->addSeries(series);
  30. QChartView *overallCarsPieChartView = new QChartView(m_chart);
  31. overallCarsPieChartView ->setRenderHint(QPainter::Antialiasing);
  32. overallCarsPieChartView ->setMinimumSize(200,200);
  33. chartLayout->addWidget( overallCarsPieChartView );
  34. overallCarsGroupBox->setLayout(chartLayout);
  35.  
  36. void MainWindow::readFile()
  37. {
  38. // ...
  39. //code to open file, parse words and tally up cars by site name
  40. // ...
  41. updateCarTotals(siteName, fords, chevys, gmcs)
  42.  
  43. }
  44.  
  45. void MainWindow::updateCarTotals(const QString &site, int fords, int chevys, int gmcs)
  46. {
  47. QString fordCount,chevyCount,gmcCount;
  48. fordCount.setNum(fords);
  49. chevyCount.setNum(chevys);
  50. gmcCount.setNum(gmcs);
  51.  
  52. totalFord+=fords;
  53. totalChevy+=chevys;
  54. totalGMC+=gmcs;
  55.  
  56. overallCarCountModel->setData(overallCarCountModel->index(0,0),QVariant(totalFord));
  57. overallCarCountModel->setData(overallCarCountModel->index(0,1),QVariant(totalChevy));
  58. overallCarCountModel->setData(overallCarCountModel->index(0,2),QVariant(totalGMC));
  59. }
To copy to clipboard, switch view to plain text mode 

In Designer, I made a MainWindow and put a TabWidget on there. Right now, I have 1 tab and on that tab I have an group box called "overallCarsGroupBox" where I want the pie chart to be displayed.

The code to read the file and tally up the cars works fine, I checked it through qDebug(). So the values being passed to MainWindow::updateCarTotals are valid. When I run the program, the title of the chart ("Total Cars") is displayed fine, but the chart does not display. Any ideas about what I could be doing wrong that would make this chart not display?