PDA

View Full Version : QTextEdit with hunspell spell checker and syntax highlighter



edogen
28th January 2011, 15:50
Hi!

I created a QTextEdit with hunspell spell checker and syntax highlighter and it allows the use of the hunspell dictionaries.
I think the project is working correctly (you can test it in the attachments, just add your language dictionary) but I read some posts about the QTextBoundaryFinder class not working correctly and I use this on my project.
Can anyone test my project and help me find if this is true.
Thanks in advance.

5835

agarny
28th January 2011, 16:15
I may have missed something, but is there any particular reason that you haven't considered using QScintilla (http://www.riverbankcomputing.co.uk/software/qscintilla/intro)?

edogen
28th January 2011, 16:20
I didn't know about QScintilla but it seems that QScintilla is focused on code editing and my approach is for writing a text document.

agarny
28th January 2011, 16:30
With regards to your text documents, do you need formatting ala Microsoft Word / OpenOffice? If so, then indeed I wouldn't expect QScintilla to be suitable for your needs.

edogen
28th January 2011, 17:27
Yes, my intention was to create a QTextEdit with spell checking and syntax highlighter like Word processing software.

Added after 48 minutes:

Hi,
the project doesn't contain any dictionary. You should insert your dictionary path in "ctextcheckeredit.cpp" (dictionaries can be found in the hunspell page).
Any questions, don't hesitate to contact me.
Thanks

bkudrle
12th November 2012, 18:45
Just to follow up on this. This is an excellent example of using Hunspell with Qt. It almost works out of the box. As edogen remarked, you need to alter the ctextcheckeredit.cpp file in order to reference a valid dictionary file. Specifically, around line 25 of ctextcheckeredit.cpp, set the dictPath value to the value to your dictionary file, and leave off the .dic of the file name. For example, you can use the en_US.dic file (download for example from here: https://github.com/rdio/vernacular/tree/master/hunspell). If you place it in the C:\temp directory (for a Windows platform), then change line 25 to


QString dictPath = "C:/temp/en_US";

Note that since it appends a .dic on the file name somewhere in the code, then you cannot use the newer OpenOffice.org versions of the dictionaries that use the .oxt extension. Once you change that, and recompile you should have a well-functioning example. Thans to edogen for posting such a well-functioning example!

TNick
12th January 2013, 16:48
Rather old thread, but, anyway,...

spellchecker.cpp contains a bug (well, two, actually) in the constructor:



QString dictFile = dictionaryPath + ".dic";
QString affixFile = dictionaryPath + ".aff";
QByteArray dictFilePathBA = dictFile.toLocal8Bit();
QByteArray affixFilePathBA = dictFile.toLocal8Bit();
_hunspell = new Hunspell(dictFilePathBA.constData(), affixFilePathBA.constData());


should be replaced by:



QString dictFile = dictionaryPath + ".dic";
QString affixFile = dictionaryPath + ".aff";
QByteArray dictFilePathBA = dictFile.toLocal8Bit();
QByteArray affixFilePathBA = affixFile.toLocal8Bit();
_hunspell = new Hunspell(affixFilePathBA.constData(), dictFilePathBA.constData());


Nick

kaufenpreis
14th September 2016, 10:47
Voted. Yes - my intention was to create a QTextEdit with spell checking and syntax highlighter like Word processing software.