Results 1 to 7 of 7

Thread: QBytearray output in single line ?

  1. #1
    Join Date
    Apr 2020
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default QBytearray output in single line ?

    Hi the board

    Sorry if my english is not fluently ( im just French and im doing my best )

    I'm really a newbie about C++ and QT just started it few days ago. Ive create a small progarm to get data from Arduino serial port, i got the data, i can parse the data as i wanted to do
    And i even save the data into csv file

    Now i have made some code to access a specific row in the file, it works i can display on textEdit, but i need to get a code to get maximum value of this specific row

    I try many code but QT debug give me reply line by line and the function std::max_element cant works correctly.... i would like to get output in one line and then execute max_element

    Ive been searching everyboard for hours, but i cant solved it alone

    Qt Code:
    1. void Dialog::on_pushButton_clicked()
    2. {
    3. {
    4.  
    5.  
    6. QString fichier2= "c:/qt/essaiqt.csv";
    7. QFile file(fichier2);
    8. if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    9. return;
    10. while (!file.atEnd())
    11.  
    12. {
    13.  
    14. QByteArray line = file.readLine();
    15. QByteArrayList fields {line.split(';')};
    16. QByteArray column2 {(fields [3])};
    17. QDataStream s(column2);
    18. fields[3] = fields [3].simplified();
    19. column2 = column2.simplified();
    20. column2.toDouble();
    21. QVector<double> essai;
    22.  
    23.  
    24. auto valeur = std::max_element(column2.begin(), column2.end());
    25. std::cout << "max "<< valeur;
    26. qDebug() << "x=" << column2;
    27.  
    28. {
    29.  
    30.  
    31. ui->textEdit->append(fields[3]);
    32.  
    33.  
    34. }
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

    and output looks like it output.png

    Your help will be highly appreciate

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QBytearray output in single line ?

    Your English is far better than my French

    I do not think your code will compile (e.g. there is no simplified() method in QDataStream and there does not seem to be a closing brace on the while() loop)

    What does "c:/qt/essaiqt.csv" contain? Something like this perhaps?
    Qt Code:
    1. 1;3359;3;4;5
    2. 1;9952;3;4;5
    3. 1;69855;3;4;5
    4. 1;3524;3;4;9999
    To copy to clipboard, switch view to plain text mode 
    What are you trying to achieve?
    • For each line, output the largest value in the line (3359, 9952, 69855, 9999), or
    • Output the largest value found in "column2" of any line (69855)

  3. #3
    Join Date
    Apr 2020
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QBytearray output in single line ?

    Quote Originally Posted by ChrisW67 View Post
    Your English is far better than my French

    I do not think your code will compile (e.g. there is no simplified() method in QDataStream and there does not seem to be a closing brace on the while() loop)

    What does "c:/qt/essaiqt.csv" contain? Something like this perhaps?
    Qt Code:
    1. 1;3359;3;4;5
    2. 1;9952;3;4;5
    3. 1;69855;3;4;5
    4. 1;3524;3;4;9999
    To copy to clipboard, switch view to plain text mode 
    What are you trying to achieve?
    • For each line, output the largest value in the line (3359, 9952, 69855, 9999), or
    • Output the largest value found in "column2" of any line (69855)
    Thanks for reply
    I would like to put it in one line and find maximum, because if i'm searching maximum on not complete line, it will give me return of each max of each line, thats why i would like to get first on one line then apply minmax et max_element

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,531
    Thanked 281 Times in 276 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QBytearray output in single line ?

    Can you show a real CSV file (several lines) and answer directly the question what does "maximum value" mean (maximum per line, column or file)? In my opinion, the description of your problem and your answers are a bit chaotic.

  5. #5
    Join Date
    Apr 2020
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QBytearray output in single line ?

    Quote Originally Posted by Lesiok View Post
    Can you show a real CSV file (several lines) and answer directly the question what does "maximum value" mean (maximum per line, column or file)? In my opinion, the description of your problem and your answers are a bit chaotic.
    serial data coming on csv file looks like it below. So i get the data of only on row with success. But i want to compare all the row i save for example row C, and get the maximum value in it

    2020-04-14 13_20_00-Microsoft Excel - serial5.png

    The problem with my code is that it compares line to line, comparing C1 with C1 and C2 with C2 because Array coming line after line i would like to compare from C1 to CXX and find max

    Hope i have explained it better now

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,531
    Thanked 281 Times in 276 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QBytearray output in single line ?

    First of all : C is a column not a row. The cell C3 lies in column C of row 3. If You want to find max value from column You can do something like this :
    Qt Code:
    1. void Dialog::on_pushButton_clicked()
    2. {
    3. QString fichier2= "c:/qt/essaiqt.csv";
    4. QFile file(fichier2);
    5. if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    6. return;
    7. double max_in_column = 0;
    8. bool first_line = true;
    9. while (!file.atEnd())
    10. {
    11. QByteArray line = file.readLine();
    12. QByteArrayList fields{line.split(';')};
    13. QString column2(fields[3])
    14. if(first_line || column2.toDouble() > max_in_column)
    15. max_in_column = column2.toDouble();
    16. first_line = false;
    17. }
    18. //here in max_in_column You have max value in column C
    19. }
    To copy to clipboard, switch view to plain text mode 
    Code not checked invented quickly.

  7. #7
    Join Date
    Apr 2020
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QBytearray output in single line ? <Solved>

    Quote Originally Posted by Lesiok View Post
    First of all : C is a column not a row. The cell C3 lies in column C of row 3. If You want to find max value from column You can do something like this :[CODE]void .
    MANY MANY THANKS !! it works perfectly !! Nice to be helped so fast and so efficient

Similar Threads

  1. Replies: 16
    Last Post: 25th February 2017, 06:50
  2. Replies: 4
    Last Post: 25th December 2014, 09:09
  3. Can I read output of a single with the help of Mingw Compiler?
    By parulkalra14 in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2014, 10:03
  4. Displaying Line by Line Output
    By parulkalra14 in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2014, 08:33
  5. Single line QTextEdit
    By Arthur in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2010, 21:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.