Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how i can identify and read the columns of a csv file ?
Forum Updated to NodeBB v4.3 + New Features

how i can identify and read the columns of a csv file ?

Scheduled Pinned Locked Moved Solved General and Desktop
49 Posts 8 Posters 7.1k Views 3 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.
  • KroMignonK KroMignon

    @JonB said in how i can identify and read the columns of a csv file ?:

    As @mrjj said, just to humour us, in the two places you have
    if(!ok)
    continue;

    please put in above the if
    Q_ASSERT(ok);

    The reason why there is continue, is because the CSV file contains the column headers, which are strings and cannot be converted to float.
    With Q_ASSERT() the program will be interrupted.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #36

    @KroMignon said in how i can identify and read the columns of a csv file ?:

    The reason why there is continue, is because the CSV file contains the column header

    Surely that's for the first line only?

    J 1 Reply Last reply
    0
    • JonBJ JonB

      @KroMignon said in how i can identify and read the columns of a csv file ?:

      The reason why there is continue, is because the CSV file contains the column header

      Surely that's for the first line only?

      J Offline
      J Offline
      julie546
      wrote on last edited by
      #37

      @JonB @mrjj @KroMignon
      I remove the headers and I replace
      if (! ok)
      continue;
      by Q_ASSERT (ok);
      but it's the same result

      KroMignonK 1 Reply Last reply
      0
      • J julie546

        @JonB @mrjj @KroMignon
        I remove the headers and I replace
        if (! ok)
        continue;
        by Q_ASSERT (ok);
        but it's the same result

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #38

        @julie546 said in how i can identify and read the columns of a csv file ?:

        I remove the headers and I replace
        if (! ok)
        continue;
        by Q_ASSERT (ok);
        but it's the same result

        I suppose it is a simple precision issue, you should replace toFloat() with toDouble():

        while (!filelidar.atEnd()) {
            QString line = filelidar.readLine();
            const auto parts = line.split (',');
            if(parts.size() >= 2)
            {
                bool ok;
                qreal x = parts.at(0).toDouble(&ok);
                if(!ok)
                {
                    qDebug() << "Could not parse X value" << parts.at(0);
                    continue;
                }
                qreal y = parts.at(1).toDouble(&ok);
                if(!ok)
                {
                    qDebug() << "Could not parse Y value" << parts.at(1);
                    continue;
                }
                series->append(x, y);
            }
        }
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        J 1 Reply Last reply
        0
        • KroMignonK KroMignon

          @julie546 said in how i can identify and read the columns of a csv file ?:

          I remove the headers and I replace
          if (! ok)
          continue;
          by Q_ASSERT (ok);
          but it's the same result

          I suppose it is a simple precision issue, you should replace toFloat() with toDouble():

          while (!filelidar.atEnd()) {
              QString line = filelidar.readLine();
              const auto parts = line.split (',');
              if(parts.size() >= 2)
              {
                  bool ok;
                  qreal x = parts.at(0).toDouble(&ok);
                  if(!ok)
                  {
                      qDebug() << "Could not parse X value" << parts.at(0);
                      continue;
                  }
                  qreal y = parts.at(1).toDouble(&ok);
                  if(!ok)
                  {
                      qDebug() << "Could not parse Y value" << parts.at(1);
                      continue;
                  }
                  series->append(x, y);
              }
          }
          
          J Offline
          J Offline
          julie546
          wrote on last edited by
          #39

          @KroMignon thank you for your answer you helped me a lot,I tried it but it's the same thing, you don't think it's about this instruction ?
          QScatterSeries * series = new QScatterSeries;
          series->setMarkerShape(QScatterSeries::MarkerShapeRectangle);

          KroMignonK JonBJ 2 Replies Last reply
          0
          • J julie546

            @mrjj
            thank you for your reply I have changed it but there are some missing points3.PNG
            QScatterSeries * series = new QScatterSeries;
            series->setMarkerShape(QScatterSeries::MarkerShapeRectangle);

            S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #40

            @julie546 said in how i can identify and read the columns of a csv file ?:

            thank you for your reply I have changed it but there are some missing points

            I am not sure that these points are actually missing. As far as I can tell you draw the points as blue squares with a white border (on a white background). If you look closely a lot of points are almost vanishing in the drawing (and some will vanish altogether). This is because the points are to close together (and some unfortunate pattern in your data) that the points overlap excactly so that you only see the white border of neighboring points (actually you don't see them as they are white on white). This makes it seem as if the points are missing.

            Try changing either the background color or the color of the borders of the data points. Or remove the border to be comparable to Excel (if that is what you want). I can't help you with the right functions as I have never used these charts.

            1 Reply Last reply
            0
            • J julie546

              @KroMignon thank you for your answer you helped me a lot,I tried it but it's the same thing, you don't think it's about this instruction ?
              QScatterSeries * series = new QScatterSeries;
              series->setMarkerShape(QScatterSeries::MarkerShapeRectangle);

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #41

              @julie546 said in how i can identify and read the columns of a csv file ?:

              series->setMarkerShape(QScatterSeries::MarkerShapeRectangle);

              This will only change the way the point is draw (https://doc.qt.io/qt-5/qscatterseries.html#markerShape-prop).
              I don't think this will change anything.

              Are you sure you have exported all points in your CSV file?
              For me, it looks like positions are missed.

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              0
              • J julie546

                @KroMignon thank you for your answer you helped me a lot,I tried it but it's the same thing, you don't think it's about this instruction ?
                QScatterSeries * series = new QScatterSeries;
                series->setMarkerShape(QScatterSeries::MarkerShapeRectangle);

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #42

                @julie546
                Your example currently has "many" points. Like anything you are trying to develop/debug, can't you cut down to something with as few points as possible while you get going? Can you go back to your original master and have like, dunno, half a dozen points (or start from 2?!), and compare how that is supposed to look against what you're getting in Qt Charts? That would eliminate all this discussion about whether you have the same number of points and whether it's just a coloring/display issue, or whatever.

                1 Reply Last reply
                1
                • J Offline
                  J Offline
                  julie546
                  wrote on last edited by
                  #43

                  it is not a problem of color nor of value because I have checked the numbers of values ​​and it is the same with the csv file and I have changed the color but it is the same graph

                  JonBJ 1 Reply Last reply
                  0
                  • J julie546

                    it is not a problem of color nor of value because I have checked the numbers of values ​​and it is the same with the csv file and I have changed the color but it is the same graph

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #44

                    @julie546
                    I still think it would help you and those trying to answer if you can reproduce a problem/difference with the absolute minimum of points to consider. Up to you.....

                    J 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @julie546
                      I still think it would help you and those trying to answer if you can reproduce a problem/difference with the absolute minimum of points to consider. Up to you.....

                      J Offline
                      J Offline
                      julie546
                      wrote on last edited by
                      #45

                      @JonB how i can change please the color of the window to black ?

                      Pl45m4P 1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        julie546
                        wrote on last edited by
                        #46

                        I tested this code but it did not change the color
                        QMainWindow window;
                        window.setCentralWidget(chartView);
                        window.resize(1000, 900);
                        window.setStyleSheet("QMainWindow {background: 'black';}");

                                               window.show(); 
                        

                        can you help me please

                        JonBJ 1 Reply Last reply
                        0
                        • J julie546

                          @JonB how i can change please the color of the window to black ?

                          Pl45m4P Offline
                          Pl45m4P Offline
                          Pl45m4
                          wrote on last edited by
                          #47

                          @julie546 said in how i can identify and read the columns of a csv file ?:

                          how i can change please the color of the window to black ?

                          https://doc.qt.io/qt-5/qtcharts-customchart-example.html

                          If you want the QChartbackground to be black, try

                          chart->setBackgroundBrush(QBrush(Qt::Black));
                          

                          For QMainWindow:

                          window.setStyleSheet("QMainWindow { background-color: black }");
                          
                          

                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          1 Reply Last reply
                          2
                          • J julie546

                            I tested this code but it did not change the color
                            QMainWindow window;
                            window.setCentralWidget(chartView);
                            window.resize(1000, 900);
                            window.setStyleSheet("QMainWindow {background: 'black';}");

                                                   window.show(); 
                            

                            can you help me please

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #48

                            @julie546
                            Try removing the quotes, window.setStyleSheet("QMainWindow {background: black;}");, and also you may need instead window.setStyleSheet("QMainWindow {background-color: black;}");?

                            1 Reply Last reply
                            1
                            • J Offline
                              J Offline
                              julie546
                              wrote on last edited by
                              #49

                              I solved the problem thank you for helping me it was because of the color
                              @JonB @J-Hilk @KroMignon @Pl45m4 @SimonSchroeder

                              1 Reply Last reply
                              1

                              • Login

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