This is not related to Qt but plain C/C++.
Just read the text file line by line, search the line for the string, and return that when found. So you have to select a file method that can read text files by line.
Such a method may be the standard C file functions (fopen,
fgets[
^], fclose) or
istream::getline[
^] with C++ input streams. Then use the standard C
strstr[
^] function to look if the line contains the keyword. Note that
strstr
is case sensitive. If you need a case insensitive search, you must implement it.
Because you want to return the content of a matching line, some kind of dynamic string should be used like
QString
.
Overall this is a typical exercise for C/C++ students. So please excuse that I'm too lazy to write some example code here.