If i am reading a line from a file and comparing it with the same text why i am not getting exact output?
Suppose i have read a line from file. ex-
- string = file.readline();
suppose now string contains “framework”.
if i am comparing by using following code
- i = string.compare("framework", Qt::CaseSensitive);
Here i should get zero but i am not getting that output.
How sure are you that the string actually is “framework”? Note that contains means that it could also read “Qt is an excellent framework” or something like that. Did you try to inspect the actual contents of string by making it debug output by setting a breakpoint?
Ya i have inspect it by taking the same string in file. I am getting the same string but followed by a character with some extra character with ascii value 127(DEL) or 255 i am not sure and then newline character.
So how can i remove that unwanted character?
Don’t just remove it, figure out where it came from first.
I am actually storing the text file in resource file. Is that is causing problem or any other thing.
- QFile file(":/New.txt");
I am not understanding why every line i am accessing is followed by the same unwanted character.
Another problem is there while i am trying to access the file as a general text file i am not able to access that file. ex-
Here i am not able to read the file.
By saying that you are not able to read the file, you mean you are getting an error? The QByteArray is null?
Also your problem with the extra character is most probably because of the file itself, not because of your application. Those extra characters are sometimes shown when reading a text file created in Windows and read in Linux.
So you could try to open it with a Notepad++ to see what goes wrong, or rewrite it and you will be fine.
Be careful with
I recommend reading QFile documentation. And, as people above suggested, look into the file itself, your problem seems to be connected with that (maybe some strange encoding?).
EDIT: Fixed the code not being wrapped in ‘@’ properly.
You’re problem with not being able to access the file with