hi i'm a new Qt user and i want to creat a new application that make a graph from csv file, so i used Qcustomplot to do so . but when i run the programm i have this message :
QCPGraph* QCustomPlot::addGraph(QCPAxis*, QCPAxis*) can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)
QCPGraph* QCustomPlot::graph(int) const index out of bounds: 0
Le programme s'est terminé subitement.
here is my programm :
#include<Fenetre.h> #include <QtWidgets> MaFenetre::MaFenetre() { setFixedSize(230,120); m_boutonDialogue = new QPushButton("importer",this); setCentralWidget(m_boutonDialogue); m_boutonDialogue->move(80,40); QObject::connect(m_boutonDialogue, SIGNAL(clicked()), this, SLOT(ouvrirDialogue())); } void MaFenetre::ouvrirDialogue() { QString fichier = QFileDialog::getOpenFileName(this, "Ouvrir un fichier", QString()); //QMessageBox::information(this, "ouvrir un fichier", fichier); QFile file(fichier); if (!file.open(QIODevice::ReadOnly)) { qDebug() << file.errorString(); } QStringList wordList,wordList2,wordList3,wordList4; while (!file.atEnd()) { QByteArray line = file.readLine(); wordList.append(line.split(';')[11]); // on recupere les valeurs de la 15 colonne wordList3.append(line.split(';')[9]); } wordList.removeFirst(); // on supprime le premier element(titre de la case) wordList3.removeFirst(); wordList2 = wordList; wordList4 = wordList3; //qDebug() << wordList2; Graph(wordList2,wordList4); } void MaFenetre::Graph(QStringList x,QStringList y) { QVector< QVector<double> > Vector1,Vector2; QVector< QVector<double> > *cVector1 = &Vector1; QVector< QVector<double> > *cVector2 = &Vector2; QVector<double> culomn1,culomn2; culomn1.clear(); culomn2.clear(); int dimension = x.count(); int dimension2 = y.count(); for(int i=0; i<dimension; i++) { culomn1.append( x.value(i).toDouble() ); } for(int i=0; i<dimension2; i++) { culomn2.append( y.value(i).toDouble() ); } qDebug()<< dimension; qDebug()<< dimension2; cVector1->append( culomn1 ); cVector2->append( culomn2 ); customPlot->addGraph(); customPlot->graph(0)->setData(culomn1, culomn2); customPlot->xAxis->setLabel("x"); customPlot->yAxis->setLabel("y"); customPlot->xAxis->setRange(-1, 1); customPlot->yAxis->setRange(0, 1); customPlot->replot(); }
the programm works fine until he arrive to customplot->addGraph().
So can you please help me out with this ?
Thank you for the responses.