Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Dictionary search

[Solved]Dictionary search

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mariusmssj
    wrote on last edited by
    #1

    Hey guys,
    I need your help I am trying to make Glossary/Dictionary. I already got the reading from file working using this:
    [code]
    void MainWindow::on_searchButton_clicked()
    {
    QString searchString = ui->lineEdit->text();
    QFile Dfile("./code_output/dictionary/dictionary.txt");
    Dfile.open(QIODevice::ReadOnly);
    QTextStream Rstream(&Dfile);
    QString dictionary = Rstream.readAll();
    Dfile.close();
    ui->textBrowser_2->append(dictionary);
    }
    [/code]

    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 =]

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mariusmssj
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mariusmssj
            wrote on last edited by
            #5

            Thanks just before i jump into it is this what you meant?

            [code]QHash <QString, QString> dictionary;[/code]

            [edit] Andre thank you a lot it works like a charm =]

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved