Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. When graphing from a file, my app stops responding
Forum Updated to NodeBB v4.3 + New Features

When graphing from a file, my app stops responding

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 2 Posters 620 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AdrianLV
    wrote on last edited by AdrianLV
    #1

    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);
                            }
            }
        }
    
    jsulmJ 1 Reply Last reply
    0
    • A AdrianLV

      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);
                              }
              }
          }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • jsulmJ jsulm

        @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.

        A Offline
        A Offline
        AdrianLV
        wrote on last edited by
        #3

        @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?

        jsulmJ 1 Reply Last reply
        0
        • A AdrianLV

          @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?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AdrianLV
            wrote on last edited by
            #5

            So, I run it in debugger and post the application output? Or what is it that I should send?

            jsulmJ 1 Reply Last reply
            0
            • A AdrianLV

              So, I run it in debugger and post the application output? Or what is it that I should send?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AdrianLV
                wrote on last edited by
                #7

                This is what I get when it gets unresponsive:

                2024-09-25_08h07_26.png

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved