PDA

View Full Version : Adding spell checking to lineedits, textedits, ...



jiveaxe
18th December 2007, 09:47
Hi,
exists some qt class which adds spell checking to editable fields like lineedits or textedits; i don't found anything in the documentation. My needs are very poor: a simple mark on the wrong word (not correction feature).

Thanks

marcel
18th December 2007, 11:01
You can go with aspell: http://aspell.net/.

smarinr
20th January 2009, 23:25
by any chance do you have any tutorial of how to integrate Aspell to QT QtextEdit???

wysota
21st January 2009, 08:45
Implement a syntax hghlighter that calls ASpell for each word using this API for example: http://aspell.net/man-html/Through-the-C-API.html#Through-the-C-API

jiveaxe
21st January 2009, 12:48
I found this project

Online spell check editor (http://www.qt-apps.org/content/show.php?content=77339)

which suit my needs. If needed I can give you some code for help.

smarinr
21st January 2009, 16:55
Thx, if you can do that I REALLY APPRECIATE!!!

jiveaxe
21st January 2009, 20:05
First list of attachments...

jiveaxe
21st January 2009, 20:07
Put all these files in your project src dir (see attachment in this and my previous post):

spelltextedit.h
spelltextedit.cpp
highlighter.h
highlighter.cpp
Aspell.h
Aspell.cpp
ThreadQueue.h
ThreadQueue.cpp

Now you can reuse the new widget SpellTextEdit like a normal QTextEdit, just "#include spelltextedit.h".

This code is different from that in the last version of "Online spell check editor"; this uses aspell instead of hspell; more: the language is hardcoded in highlighter.h so if needed look there.

Regards

smarinr
21st January 2009, 20:40
This needs something else from aspell?

jiveaxe
22nd January 2009, 08:01
This needs something else from aspell?

All you need is aspell program, no libs.

Bye

AviMittal
29th July 2009, 09:17
Can you please elaborate how to use these files within project. I want to add spell checking functionality to my QtextEdit.

jiveaxe
29th July 2009, 11:04
Simply use SpellTextEdit instead of QTextEdit (remember to edit highlighter.h for setting your language). Just a little example:


#include <QApplication>
#include "spelltextedit.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
SpellTextEdit *spellTextEdit = new SpellTextEdit;
spellTextEdit->show();
return app.exec();
}

Attached are 2 files; use these instead of those in my previous posts;

Bye

izogfif
7th October 2009, 09:04
---<summary>---
QtWebKit doesn't mark (underline with red wavy line) misspelled words
while in designMode even if spell checking is implemented and works
correctly. Could you please point me what I am doing wrong?
I'm building arora with QtWebKit (actually, entire qt 4.6.0 tp1
downloaded from qt web site as tarball) using Visual Studio 2005 SP1
under English WIndows XP SP3.
---</summary>---

Recently I have been interested in embedding QtWebKit in my project as
webbrowser plugin. I looked around the web and found arora excellent
example for implementing code that covers my needs. But I'm also need
to enable spell checking in QtWebkit. To do so I've taken another look
at Google Chrome source code that might use hunspell to enable
spellchecking in browser and found some clues. I have rewritten
Chromium's code and replaced following functions in

qt-4.6.0-tp1\src\3rdparty\webkit\WebKit\qt\WebCoreSupport\E ditorClientQt.cpp


void EditorClientQt::checkSpellingOfString(const UChar* str, int length,
int* misspellingLocation,
int* misspellingLength)
{
// Original
// notImplemented();
return MySpellChecker::getInstance()->checkSpellingOfString(str,
length, misspellingLocation, misspellingLength);
}

bool EditorClientQt::isContinuousSpellCheckingEnabled()
{
// Original
// return false;
return true;
}

String EditorClientQt::getAutoCorrectSuggestionForMisspel ledWord(const
String &word)
{
//Original
//notImplemented();
//return String();
return MySpellChecker::getInstance()->getAutoCorrectSuggestionForMisspelledWord(word);
}

MySpellChecker is spellchecker that using hunspell. I've built
QtWebKit and placed breakpoints inside bodies of functions mentioned
above. As far as I can see functions are being invoked correctly, i.e.
if I, for example, write "cra is moving", it is being corrected by
getAutoCorrectSuggestionForMisspelledWord as "car is moving", but if i
write "car is asdf" then the word "asdf" is just not being marked as
misspelled word. Could you please point me what I am doing wrong?

I'm building arora with QtWebKit (actually, entire qt 4.6.0 tp1
downloaded from qt web site as tarball) using Visual Studio 2005 SP1
under English WIndows XP SP3.