Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
I need your help I am trying to make Glossary/Dictionary. I already got the reading from file working using this:
QString searchString = ui->lineEdit->text();
QString dictionary = Rstream.readAll();
which outputs the content of the dictionary.text file. what I want to do now is when I press the search button that it would compare the the word that I typed in the search text field against the world in every line up to ":" as the layout of the .txt file is this:
[code]This : This - works
is : is - works
a : a - works
test : text - works[/code]
So basically it would compare words from the .txt up until ":" and then output any text after the ":" if matched. As English is not my first language I'm not sure what to look for. Any tips on how I could do it?
Thank you =]
andre last edited by
How big is this dictionairy of yours going to be?
What I would considder as a first, simple approach, is to load your whole dictionairy once, and put all the data in a QHash<QString, QString> structure. Then, when you want to search, you only need to check your hash to see if the item exists, and that can be done quite efficiently. Of course, this only works if the size of the dictionairy is not too big, otherwise it would consume too much memory. On the other hand, you also do not want to lineairy search a big dictionairy from disk every time.
If you dictionairy is going to grow, you might considder using a database instead, and making sure the tables in it are indexed.
Hey Andre, my dictionary is only going to store 60 entries max + a description for each entry, basically I am doing OpenGl function and attribute look up. You type in a function name or an attribute name click search and you get a description on a texbox below.
andre last edited by
So just load the whole thing into a single QHash and use that instead of doing a linear search through a file on disk each time.
Thanks just before i jump into it is this what you meant?
[code]QHash <QString, QString> dictionary;[/code]
 Andre thank you a lot it works like a charm =]