1 Attachment(s)
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
Code:
void Dialog::on_pushButton_clicked()
{
{
QString fichier2
= "c:/qt/essaiqt.csv";
return;
while (!file.atEnd())
{
QByteArrayList fields {line.split(';')};
fields[3] = fields [3].simplified();
column2 = column2.simplified();
column2.toDouble();
QVector<double> essai;
auto valeur = std::max_element(column2.begin(), column2.end());
std::cout << "max "<< valeur;
qDebug() << "x=" << column2;
{
ui->textEdit->append(fields[3]);
}
}
}
and output looks like it Attachment 13380
Your help will be highly appreciate :cool:
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?
Code:
1;3359;3;4;5
1;9952;3;4;5
1;69855;3;4;5
1;3524;3;4;9999
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)
Re: QBytearray output in single line ?
Quote:
Originally Posted by
ChrisW67
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?
Code:
1;3359;3;4;5
1;9952;3;4;5
1;69855;3;4;5
1;3524;3;4;9999
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
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.
1 Attachment(s)
Re: QBytearray output in single line ?
Quote:
Originally Posted by
Lesiok
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
Attachment 13381
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 :D
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 :
Code:
void Dialog::on_pushButton_clicked()
{
QString fichier2
= "c:/qt/essaiqt.csv";
return;
double max_in_column = 0;
bool first_line = true;
while (!file.atEnd())
{
QByteArrayList fields{line.split(';')};
if(first_line || column2.toDouble() > max_in_column)
max_in_column = column2.toDouble();
first_line = false;
}
//here in max_in_column You have max value in column C
}
Code not checked invented quickly.
Re: QBytearray output in single line ? <Solved>
Quote:
Originally Posted by
Lesiok
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 :cool: