there's a text editing widget in my QT Widget application. My menu item checks to see if the text edit below is empty. Thus, I'm trying to create a function that checks and returns true/false depending on the situation. Can anyone help me?
Asked
Active
Viewed 495 times
-3
-
Please add code showing what you have tried. – David K. Hess Jan 31 '22 at 14:12
2 Answers
3
Here's a simple way to do it (illustrated with a function, for clarity):
bool IsTextEditEmpty(const QTextEdit * myTextEdit)
{
return myTextEdit->document()->isEmpty();
}

Jeremy Friesner
- 70,199
- 15
- 131
- 234
-
I appreciate your help a lot. It was an ideal way to go about it. I checked the length earlier by exporting the TextEdit file to plain text. Using this method is more efficient. Many thanks. – Feb 01 '22 at 04:25
0
There is no need for any function QML TextEdit has length property, simply reading this property and evaluating as bool will return true if TextEdit has non-empty text and false on empty text.

Octopussy
- 128
- 2
- 10
-
-
-
It wasn't clear from the question, TextEdit was mentioned instead of QTextEdit along with the qml tag – Octopussy Feb 01 '22 at 21:12