`find()` to search for the newline character via QRegExp
-
@Gojir4
Is that really what you use in your C++ source code?? Those\r
&\n
s are going to be passed as literal carriage-returns/newlines to construct the regular expression, which to me is not a good idea at all.Better surely (standard C++)
QRegularExpression("\u2029|\\r\\n|\\r|\\n")
-
@tamlok
Sorry, OK to the\x
rather than the\u
, I'm not a C++-er.In that case, I presume your "does not work" means that you have checked the return result of your
QTextEdit::find(QRegExp("\x2029"))
and that's false, right? What makes you think your text even has a\x2029
anywhere in it? If it's not finding it, I presume it does not. -
@tamlok said in `find()` to search for the newline character via QRegExp:
find() seems only have QRegExp overloaded prototype
You can specify a PatternSyntax like
QRegExp::FixedString
,QRegExp::Wildcard
, if you don't want to use regular expression.@tamlok said in `find()` to search for the newline character via QRegExp:
BTW, do you know why find(QRegExp("$")) will hang the application?
Not really. That's seems strange. But probably this pattern is not well supported by QRegExp. There are some limitations with this class. That's the reason QRegularExpression was added in Qt to replace QRegExp. Unfortunately only QRegExp is currently supported with
QTextEdit::find()
. -
@Gojir4 said in `find()` to search for the newline character via QRegExp:
@tamlok said in `find()` to search for the newline character via QRegExp:
find() seems only have QRegExp overloaded prototype
You can specify a PatternSyntax like
QRegExp::FixedString
,QRegExp::Wildcard
, if you don't want to use regular expression.No, I do want to use
QRegExp
to search for the "Paragraph Separator". But it seems not work (QRegExp("\x2029")
).@tamlok said in `find()` to search for the newline character via QRegExp:
BTW, do you know why find(QRegExp("$")) will hang the application?
Not really. That's seems strange. But probably this pattern is not well supported by QRegExp. There are some limitations with this class. That's the reason QRegularExpression was added in Qt to replace QRegExp. Unfortunately only QRegExp is currently supported with
QTextEdit::find()
.Emm... Seems that I have nothing to do but handle the corner cases manually.
-
@JonB said in `find()` to search for the newline character via QRegExp:
@tamlok
Sorry, OK to the\x
rather than the\u
, I'm not a C++-er.In that case, I presume your "does not work" means that you have checked the return result of your
QTextEdit::find(QRegExp("\x2029"))
and that's false, right? What makes you think your text even has a\x2029
anywhere in it? If it's not finding it, I presume it does not.I am sure the text will have
\x2029
because I have multiple lines and paragraphs inQTextEdit
, which surely has the "Paragraph Separator".Anyway, it seems that
QRegExp
does not supoprt that well. -
@tamlok
That\x
pattern then is actually recognised byQRegExp
. You do not just want to pass the C character, I think. So try:QTextEdit::find(QRegExp("\\x2029"))
?Also read up the hidesousness of https://stackoverflow.com/questions/22838656/what-qstring-can-not-pass-a-qregexp-of-the-form-x00-xff
-
I think you can use
QTextCursor::move(QTextCursor::EndOfLine)
as an alternative.Are you using the QTextEdit::find() interface? find() seems only have QRegExp overloaded prototype
This will be solved in Qt 5.13 thanks to @SGaist: https://codereview.qt-project.org/224913/