How can i solve no matching member function for call to 'append' ??
Unsolved
General and Desktop
-
Hi guys. I got an error in series-> append part. It says no matching member function for call to append. How can i solve it?
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QTextStream> #include <QtCharts/QLineSeries> #include <QtCharts/qlineseries.h> #include <QLine> #include <qline.h> using namespace QtCharts; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_2_clicked() { QLineSeries *series = new QLineSeries(); QFile file("C:/Users/ilknu/Documents/Dendennnnden/ornek.txt"); if(file.open(QIODevice::ReadOnly)) { QTextStream in (&file); while(!in.atEnd()) { QString line = in.readLine(); QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); for(const QString &entry : list) { double num = entry.toDouble(); series->append(num); } } } }
-
Hi,
@suslucoder said in How can i solve no matching member function for call to 'append' ??:
double num = entry.toDouble();
series->append(num);Please, read the documentation, there's no append overload which takes a double.
-
Please show your current code and the exact error.
-
@SGaist Here is the current code
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QTextStream> #include <QMessageBox> #include <QTimer> #include <QList> #include <qlist.h> #include <QDebug> #include <QtCharts/QLineSeries> #include <QtCharts/QChart> #include <QtCharts/QDateTimeAxis> #include <QDateTime> #include <QtCharts/QValueAxis> #include <QtCharts/QChartView> #include <QLine> #include <QString> QT_CHARTS_USE_NAMESPACE using namespace QtCharts; QTimer *timer = new QTimer(); MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); connect(timer, SIGNAL(timeout()), SLOT(Timer_Slot())); } void MainWindow::Timer_Slot() { QString line = allLines[curIndex]; ui->plainTextEdit->setPlainText(line); if (curIndex < allLines.size() - 1 ) { curIndex++; } } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_2_clicked() //write { QFile file("C:/Users/ilknu/Documents/QFileDemo/abc.txt"); if(!file.open(QFile::WriteOnly | QFile::Text )) { QMessageBox::warning(this, "title", "file not open"); } QTextStream out (&file); QString text = ui->plainTextEdit->toPlainText(); out << text; file.flush(); file.close(); } void MainWindow::on_pushButton_clicked() //read { QLineSeries *series = new QLineSeries(); QFile file("C:/Users/ilknu/Documents/QFileDemo/abc.txt"); if (file.open(QIODevice::ReadOnly)) { QTextStream in (&file); while (!in.atEnd()) { //QString line = in.readLine(); //allLines.append(line); QString line = in.readLine(); allLines.append(line); QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); for(const QString &entry : list) { double num = entry.toDouble(); qDebug()<<num; series->append(num); } } } file.close(); curIndex=0; timer->start(200); }
-
@suslucoder said in How can i solve no matching member function for call to 'append' ??:
series->append(num);
That line is still wrong. The append method takes two arguments representing a coordinate or one that is a QPointF or finally a list of QPointF.