PDA

View Full Version : Find function in Qt ?



npc
8th May 2006, 15:13
Hi folks,

Is there any function in Qt to find a string in a file.

Or any other solution to get a needed text instead of reading line by line.

Thanks,
-;)

wysota
8th May 2006, 17:21
QFile f("somefile");
f.open(QIODevice::ReadOnly);
QString data = f.readAll();
int i = data.indexOf("Find me");

npc
9th May 2006, 09:31
Thank you very much wysota.

Could you tell me how to remove a particular line from the file,
or replace that line by some other line, completely.

Thanks
-;)

jpn
9th May 2006, 10:06
how to remove a particular line from the file, or replace that line by some other line, completely.
Then it's probably easiest to simply read line by line, for example append all read (and possibly modified/replaced) lines to a string(list) and then write it back to the file. You cannot remove data from the middle of a file. You have to read it all, modify, and then re-write the file.