When graphing from a file, my app stops responding
-
Hello there,
I am trying to plot from a file using QtCharts in QtQuick. I think the way I am doing it is not the best way of doing it, because I tried even plotting something small but it is still not working. I would think that maybe Qt is not great for this kind of plots, but I had a Widget App that was doing basically the same and working. I also tried returning the vectors, but it was not allowing me access to the information.
Thank you for your time, any help would be really helpful!
Here is an overview of my program:
classmanager.cpp:
bool fileManager::readFromFile(const QString &fileName) { QString filePath = fileName; QUrl url(fileName); QFile file(url.toLocalFile()); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qWarning() << "Could not open file for reading: " << filePath; return false; } dataManager dataManager; QVector<double> xDataOpenRaw; QVector<double> yDataOpenRaw; QVector<double> zDataOpenRaw; QVector<double> xDataOpenMs2; QVector<double> yDataOpenMs2; QVector<double> zDataOpenMs2; xData.clear(); yData.clear(); zData.clear(); QTextStream in(&file); double time = 0.0; while(!in.atEnd()){ QString line = in.readLine(); line = line.left(line.length() - 1); QStringList values = line.split(','); if(values.size() == 3){ bool ok; xDataOpenRaw.append(values[0].trimmed().toDouble()); xDataOpenMs2.append(dataManager.fullConvertion(values[0].toLongLong(&ok))); xData.append(QPointF(time,dataManager.fullConvertion(values[0].toLongLong(&ok)))); yDataOpenRaw.append(values[1].trimmed().toDouble()); yDataOpenMs2.append(dataManager.fullConvertion(values[1].toLongLong(&ok))); yData.append(QPointF(time,dataManager.fullConvertion(values[1].toLongLong(&ok)))); zDataOpenRaw.append(values[2].trimmed().toDouble()); zDataOpenMs2.append(dataManager.fullConvertion(values[2].toLongLong(&ok))); zData.append(QPointF(time,dataManager.fullConvertion(values[2].toLongLong(&ok)))); time += .01; if(xData.size() % 100 == 0){ emit dataUpdated(); } }else{ totalTimeOpen = values[0].toDouble(); } } if(totalTimeOpen == 0.0){ totalTimeOpen = -1; } emit dataUpdated(); file.close(); qDebug() << "Data read from file: " << filePath; return true; }Main.qml:
ChartView { id: chartViewOpen title: "Open File Acceleration" anchors.fill: parent antialiasing: true ValuesAxis{ id: timeAxisOpen titleText: "Time (s)" } ValuesAxis { id: valueAxisOpen titleText: "Acceleration (m/s²)" } LineSeries{ id: xOpenSeries name: "x Axis" axisX: timeAxisOpen axisY: valueAxisOpen XYPoint{x: 0; y: 0} XYPoint{x: 1; y: 1} XYPoint{x: 2; y: 2} XYPoint{x: 3; y: 3} } } Connections { target: fileManager onDataUpdated: { for (var i = xOpenSeries.count; i < fileManager.xData.length; i++) { xOpenSeries.append(fileManager.xData[i].x, fileManager.xData[i].y); } } } -
Hello there,
I am trying to plot from a file using QtCharts in QtQuick. I think the way I am doing it is not the best way of doing it, because I tried even plotting something small but it is still not working. I would think that maybe Qt is not great for this kind of plots, but I had a Widget App that was doing basically the same and working. I also tried returning the vectors, but it was not allowing me access to the information.
Thank you for your time, any help would be really helpful!
Here is an overview of my program:
classmanager.cpp:
bool fileManager::readFromFile(const QString &fileName) { QString filePath = fileName; QUrl url(fileName); QFile file(url.toLocalFile()); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qWarning() << "Could not open file for reading: " << filePath; return false; } dataManager dataManager; QVector<double> xDataOpenRaw; QVector<double> yDataOpenRaw; QVector<double> zDataOpenRaw; QVector<double> xDataOpenMs2; QVector<double> yDataOpenMs2; QVector<double> zDataOpenMs2; xData.clear(); yData.clear(); zData.clear(); QTextStream in(&file); double time = 0.0; while(!in.atEnd()){ QString line = in.readLine(); line = line.left(line.length() - 1); QStringList values = line.split(','); if(values.size() == 3){ bool ok; xDataOpenRaw.append(values[0].trimmed().toDouble()); xDataOpenMs2.append(dataManager.fullConvertion(values[0].toLongLong(&ok))); xData.append(QPointF(time,dataManager.fullConvertion(values[0].toLongLong(&ok)))); yDataOpenRaw.append(values[1].trimmed().toDouble()); yDataOpenMs2.append(dataManager.fullConvertion(values[1].toLongLong(&ok))); yData.append(QPointF(time,dataManager.fullConvertion(values[1].toLongLong(&ok)))); zDataOpenRaw.append(values[2].trimmed().toDouble()); zDataOpenMs2.append(dataManager.fullConvertion(values[2].toLongLong(&ok))); zData.append(QPointF(time,dataManager.fullConvertion(values[2].toLongLong(&ok)))); time += .01; if(xData.size() % 100 == 0){ emit dataUpdated(); } }else{ totalTimeOpen = values[0].toDouble(); } } if(totalTimeOpen == 0.0){ totalTimeOpen = -1; } emit dataUpdated(); file.close(); qDebug() << "Data read from file: " << filePath; return true; }Main.qml:
ChartView { id: chartViewOpen title: "Open File Acceleration" anchors.fill: parent antialiasing: true ValuesAxis{ id: timeAxisOpen titleText: "Time (s)" } ValuesAxis { id: valueAxisOpen titleText: "Acceleration (m/s²)" } LineSeries{ id: xOpenSeries name: "x Axis" axisX: timeAxisOpen axisY: valueAxisOpen XYPoint{x: 0; y: 0} XYPoint{x: 1; y: 1} XYPoint{x: 2; y: 2} XYPoint{x: 3; y: 3} } } Connections { target: fileManager onDataUpdated: { for (var i = xOpenSeries.count; i < fileManager.xData.length; i++) { xOpenSeries.append(fileManager.xData[i].x, fileManager.xData[i].y); } } } -
@AdrianLV "my app breaks" - what does this mean? Is it crashing? Please explain better what is happening. If it is crashing then please post the stack trace after the crash.
-
@jsulm
It is not crashing, it just stops responding. I have not seen if there is a stack trace, after having to close the no responding window. Is this visible in the Application Output?@AdrianLV said in When graphing from a file, my app stops responding:
Is this visible in the Application Output?
In debugger. So, run your app in debugger.
-
So, I run it in debugger and post the application output? Or what is it that I should send?
@AdrianLV said in When graphing from a file, my app stops responding:
Or what is it that I should send?
Stack trace when the app becomes unresponsive
