您如何声明/使“ QBarSet”成为数组?

时间:2019-06-09 21:51:23

标签: c++ qt

我是QT GUI /小部件以及类和指针的新手。我有一项作业,要求我使用QT Widget制作条形图。但是,我正在尝试在代码中实现一个数组以使其更加整洁。

这是代码的一部分:

    //assign names to the set of bars used
    QBarSet *set0 = new QBarSet("Jane");
    QBarSet *set1 = new QBarSet("John");
    QBarSet *set2 = new QBarSet("Axel");
    QBarSet *set3 = new QBarSet("Mary");
    QBarSet *set4 = new QBarSet("Samantha");

    //assign values for each bar
    *set0 << 1 << 2 << 3 << 4 << 5 << 6;
    *set1 << 5 << 3 << 6 << 4 << 2 << 7;
    *set2 << 3 << 5 << 8 << 10 << 8 << 5;
    *set3 << 5 << 6 << 7 << 3 << 4 << 5;
    *set4 << 9 << 7 << 5 << 3 << 1 << 2;

    //add all sets of data to the chart as a whole
    //1. Bar Chart
    QBarSeries *series = new QBarSeries();
    //2. Stacked Bar Chart
    series->append(set0);
    series->append(set1);
    series->append(set2);
    series->append(set3);
    series->append(set4);

正如您在上面看到的,我正在尝试使set变量成为数组。我该怎么办?

0 个答案:

没有答案