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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With