Qt World Summit: Register Today!

Words to completion

  • Hellow, there is example "custom completer" and there is a txt file, where write words to completion, i change file on the file with my words, and program stopped to complet. Among all words program complete only first word - top
    "My text file":http://www.forum.crossplatform.ru/index.php?act=attach&type=post&id=1371
    What am I doing wrong, i redaction file in the Windows notebook and in the Notepad++ with "\n" - program doesnt worked
    Thanks in advance! And sorry for my vary bad english!

  • Have you tried debugging the example to see if the file gets loaded correctly?

  • Yes i am compiled example with my file and there complet only first word in the list - "top"

  • That's not what I asked. I asked if you had executed the application in a debugger and stepped through it line by line where the file is loaded and actually inspected the affected variables in the debugger to make sure they contain the contents of the entire file.

  • Yes, I tested it - file read correctly.
    I noticed the following feature - if in the standart file with words(file, witch example use by default) wrie some word then program doesnt worked, i think that problem in the sign of "a new line" or other separator

  • I find in the code of textEdit interesting string:
    static QString eow("~!@#$%^&*()_+{}|:"<>?,./;'[]\-="); // end of word
    How i can think it is mean that after all words in the list i must write one of the following signs, i am try but program also dont work and in the example list there are no some signs after words

  • Help me, plaease, i am a beginner in the Qt

  • Please practise some patience. Allow for at least 24 hours before "kicking" your topic.

  • Please excuse me, of course I'll wait as much as you want, I just thinking that you forgot about my problem.
    And once again many thanks for your help!

  • Not forgotten about you. We have day jobs too and do need some personal time too sometimes ;-)

    I'm just back from a swim. I'll try to take a look at it tonight after I've had some food.

  • OK I can reproduce the problem - even with a trimmed down version of your wordslist.txt file that removes anything other than [a-z]. I also tried converting line endings to unix style to no avail.

    It appears as if the QStringListModel is being correctly populated from the file so th eproblem must lie deeper.

    I'll need to dig into Qt itself to see what is going wrong so it may take me a little while.

  • OK forget that. I've figured it out. The problem is you are breaking an assumption of that example. In the constructor of the custom completer example you'll see this line of code:


    This tells the app that the supplied word list is already sorted which allows the completer to make some optimisations when searching for matching completions (I would imagine it uses a bisection search rather than linear search but I have not checked).

    Your word list is not sorted which breaks that pre-condition. To fix it you can either

    Sort your wordlist so that it matches the above condition (ie sorted case insensitively)

    Change the example to use QCompleter::UnsortedModel

    I recommend option 1. When I did this (using the sort command under linux) it worked perfectly.

  • Many thinks for your help, it is worked!

Log in to reply