Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt C++ QTextEdit count words while typing

Tags:

c++

qt

I need to implement method in Qt C++ which counts number of words in QTextEdit while user type. Also when user type multiple spaces they shouldn't be treated as word. I know how to do this on already typed text, but I need to update total number of words all the time. Can you help me with this.

like image 697
Alen Avatar asked Nov 12 '22 07:11

Alen


1 Answers

I would suggest you to connect on void QTextEdit::textChanged () [signal] and use something like this:

void onTextChanged()
{
    int wordCount = textEdit->toPlainText().split(QRegExp("(\\s|\\n|\\r)+")
                                                  , QString::SkipEmptyParts).count();
}
like image 59
Amartel Avatar answered Nov 14 '22 23:11

Amartel