How to use QFile, QByteArray and QString?
-
@victor-wang And what is the problem? Just read line by line the first 6 lines.
-
@victor-wang And what is the problem? Just read line by line the first 6 lines.
@jsulm
That because if there is other person who want to write things into eeprom.
I will show what he write in the eeprom.
According to this addition, I can't just read for six lines.
Because not every one will just write 6 lines.I have to know where is the last word.
-
@jsulm
That because if there is other person who want to write things into eeprom.
I will show what he write in the eeprom.
According to this addition, I can't just read for six lines.
Because not every one will just write 6 lines.I have to know where is the last word.
@victor-wang Again: what is "last word"? How is it defined? I still don't understand what information you want to get. Are those MAC2, Model, PN, ...?
-
@victor-wang Again: what is "last word"? How is it defined? I still don't understand what information you want to get. Are those MAC2, Model, PN, ...?
For example the picture i gave you.
The last word means the last line of the "6".
Picture hereThose words is what i write in eeprom.
For other example if i write "skdjb,smdnv6546321" into eeprom.
Then the last Alphabet is "1" and i just want to read what i write. -
For example the picture i gave you.
The last word means the last line of the "6".
Picture hereThose words is what i write in eeprom.
For other example if i write "skdjb,smdnv6546321" into eeprom.
Then the last Alphabet is "1" and i just want to read what i write.@victor-wang Then read line by line and parse each line to check whether it is what you want.
And you should use correct wording, else it's hard to understand what you mean: a word is not a line. -
@victor-wang Then read line by line and parse each line to check whether it is what you want.
And you should use correct wording, else it's hard to understand what you mean: a word is not a line.@jsulm
Sorry, how to parse it?
I will not know what will other people write, how can parse? -
@jsulm
Sorry, how to parse it?
I will not know what will other people write, how can parse?@victor-wang OK, you don't know what others are writing, right? But you know what you want to read, right?
If so then:QByteArray whatIWantToRead = "ABCD"; QString line = file.readLine(); if (line == whatIWantToRead) // do something
-
@victor-wang OK, you don't know what others are writing, right? But you know what you want to read, right?
If so then:QByteArray whatIWantToRead = "ABCD"; QString line = file.readLine(); if (line == whatIWantToRead) // do something
@jsulm
If i want to read a~z、A~Z and some other exclamation mark and question mark and etc..
I have to write all of it into whatIWantToRead ? -
@jsulm
If i want to read a~z、A~Z and some other exclamation mark and question mark and etc..
I have to write all of it into whatIWantToRead ?@victor-wang You can use regular expressions, see https://en.wikipedia.org/wiki/Regular_expression and http://doc.qt.io/qt-5.8/qregularexpression.html
-
@victor-wang You can use regular expressions, see https://en.wikipedia.org/wiki/Regular_expression and http://doc.qt.io/qt-5.8/qregularexpression.html
@jsulm
Do you have an example?
Or can i parse it by ASCII ? -
@jsulm
Do you have an example?
Or can i parse it by ASCII ?@victor-wang There are a lot of examples for regular expressions on the Internet
-
@jsulm
Do you have an example?
Or can i parse it by ASCII ?If you know, that valid lines always contain legit chars between 'A' and 'z'
You can make a simple If-statement with the first char in your bytearray:
QByteArray bArray = file.readline(); if(bArray[0] < QLatin1Char('A') || bArray[0] > QLatin1Char('z')) //Abort condition met
use QLatin1Char if its ASCII, QChar if its unicode.