我有一个 QT 应用程序,在我的窗口上我有图表,图表的数量取决于用户的选择,这就是我使用指针数组来创建它们的原因。我的问题是当我尝试在我的 QChart(已经有 QScatterSeries)上添加 QLineSeries 对象时,这条线只添加到最后一个图表上。这是我的代码示例:
图.h
QChart *chartArr[chartLimit];
QLineSeries *lineArr[lineLimit];
QPushButton *nextButton;
public slots:
onnextButtonClicked();
图.cpp
GraphDialog::GraphDialog(QWidget *parent, Form *formPtr) :
QDialog(parent),
ui(new Ui::GraphDialog)
{
...
this->nextbutton = new QPushButton(buttonFrame);
connect(this->nextbutton,SIGNAL(clicked()),this,SLOT(onnextButtonClicked()));
...
}
void Graph::createLine(QString selected_item)
{
if(selected_item == "300") //seleted_item is the item what user choose on comboBox object
{
this->lineArr[0] = new QLineSeries();
this->lineArr[0]->setName("300-350gr");
this->lineArr[0]->append(QPoint(this->dy,this->y_max)); //variables that app calculated on previous functions. On debug mode this varibales seen calculated succesfully.
this->lineArr[0]->append(QPoint(this->dy,0));
}
}
void Graph::fillCharts(int index,QString selected_item)
{
if(selected_item == "300")
{
this->chartArr[index]->addSeries(this->lineArr[0]);
this->chartArr[index]->createDefaultAxes();
}
}
void Graph::onnextButtonClicked(){
QString selected_item = this->comboBox->currentText();
if(selected_item == "300"){
this->createLine("300");
for(int i = 0 ;i<this->chartIndexList.count();i++){ //this list holds my chart indexes and when I debug I could see list filled succesfully
if(this->chartIndexList.at(i) != 0){
this->fillCharts(this->chartIndexList.at(i),"300");
}
}
}
}