Creating a chart with multiple datas
-
@Pl45m4 said in
Do you even read what we wrote?
Of course. I just confused.
QString file("/home/ilknur/FourLineChart/Data1.txt"); QString file2("/home/ilknur/FourLineChart/Data2.txt"); QString file3("/home/ilknur/FourLineChart/Data3.txt"); QString file4("/home/ilknur/FourLineChart/Data4.txt"); MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); CreateChart(); ReadFile(file); ReadFile(file2); ReadFile(file3); ReadFile(file4); void MainWindow::ReadFile(QString file) { QFile(file); if(file.open(QIODevice::ReadOnly)) { QTextStream in(&file); while (!in.atEnd()) { QString line = in.readLine(); QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts); for (const QString &entry : list) { double num = entry.toDouble(); qDebug() << num; // pick correct queue here queue.enqueue(num); } } } }
I miss something. But i dont know.
-
@suslucoder I really don't understand why it is so hard! Please try to figure out such trivial things by yourself.
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); CreateChart(); QString file("/home/ilknur/FourLineChart/Data1.txt"); QString file2("/home/ilknur/FourLineChart/Data2.txt"); QString file3("/home/ilknur/FourLineChart/Data3.txt"); QString file4("/home/ilknur/FourLineChart/Data4.txt"); ReadFile(file); ReadFile(file2); ReadFile(file3); ReadFile(file4);
Or shorter:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); CreateChart(); ReadFile("/home/ilknur/FourLineChart/Data1.txt"); ReadFile("/home/ilknur/FourLineChart/Data2.txt"); ReadFile("/home/ilknur/FourLineChart/Data3.txt"); ReadFile("/home/ilknur/FourLineChart/Data4.txt");
-
@jsulm said in Creating a chart with multiple datas:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
CreateChart();
ReadFile("/home/ilknur/FourLineChart/Data1.txt");
ReadFile("/home/ilknur/FourLineChart/Data2.txt");
ReadFile("/home/ilknur/FourLineChart/Data3.txt");
ReadFile("/home/ilknur/FourLineChart/Data4.txt");I've do it in that way and i have
void MainWindow::ReadFile(QString file) { QFile(file); if(file.open(QIODevice::ReadOnly)) { QTextStream in(&file); while (!in.atEnd()) { QString line = in.readLine(); QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts); for (const QString &entry : list) { double num = entry.toDouble(); qDebug() << num; // pick correct queue here queue.enqueue(num); } } } }
I've got a lot of errors:
: In member function ‘void MainWindow::ReadFile(QString)’:
: error: declaration of ‘QFile file’ shadows a parameter
error: declaration of ‘QFile file’ shadows a parameter
QFile(file);
^ -
@suslucoder said in Creating a chart with multiple datas:
QFile(file);
Again easy to fix:
void MainWindow::ReadFile(QString filePath) { QFile file(filePath); if(file.open(QIODevice::ReadOnly))
-
@jsulm okey. We did it in that way. But i have
void MainWindow::Timer_Slot() { static float q_x=0; static float q_x2=0; static float q_x3=0; static float q_x4=0; if(!queue.isEmpty()) { double num=queue.dequeue(); q_x += 0.1; series->append(q_x, num); chart->scroll(10, 0); chart->update(); qDebug() << q_x << num; } if(!queue2.isEmpty()) { double num2=queue2.dequeue(); q_x2 += 0.1; series2->append(q_x2, num2); chart->scroll(10, 0); chart->update(); qDebug() << q_x2 << num2; } if(!queue3.isEmpty()) { double num3=queue3.dequeue(); q_x3 += 0.1; series3->append(q_x3, num3); chart->scroll(10, 0); chart->update(); } if(!queue4.isEmpty()) { double num4=queue4.dequeue(); q_x4 += 0.1; series4->append(q_x4, num4); chart->scroll(10, 0); chart->update(); } }
What will happen my other queues, in ReadFile() ?
-
@suslucoder said in Creating a chart with multiple datas:
What will happen my other queues, in ReadFile() ?
Can't you simply use one queue?
If not then extend the readFile() method:void MainWindow::ReadFile(const QString &file, QQueue<double> &queue) { ...
And pass queue as second parameter.
-
@jsulm said in Creating a chart with multiple datas:
Can't you simply use one queue?
When i use one queue, how can i differ my datas?
Txt files have different values, and i will show all of them in a line chart with different color -
@suslucoder Then do like I suggested:
void MainWindow::ReadFile(const QString &file, QQueue<double> &queue) { ... } ... ReadFile("/home/ilknur/FourLineChart/Data1.txt", queue); ReadFile("/home/ilknur/FourLineChart/Data2.txt", queue1); ReadFile("/home/ilknur/FourLineChart/Data3.txt", queue2); ReadFile("/home/ilknur/FourLineChart/Data4.txt", queue3);
-
-
This post is deleted!