Storing enum in a list?
-
I'm making a simple find and replace function for my text editor. And there are a few checkbox for the flnd flags like "match case" and "whole words". When the find button is clicked, the checkbox selections will be stored in a
QMap<QString, bool>and send along with the search text to the find function.In the find function I will unpack the findFlags QMap and check their state to add flags like
QTextDocument::FindCaseSensitivelyto the find function. I want to store these enum in something like a QStringList that at the end I can paste them in the find function in one go like this.editor->find(a_text, findFlagsList.join(" | ")) // I want it to print out like this editor->find(a_text, QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords) -
Hi
But why a string list ?
You can just store them as QFlags<FindFlag>
And give that directly to editor->find
You can no do that with strings. -
Hi
But why a string list ?
You can just store them as QFlags<FindFlag>
And give that directly to editor->find
You can no do that with strings. -
Hi I tried
QFlags<FindFlag> findFlagsbut I got the errorunknown type name 'FindFlag'Hi
ItsQFlags<QTextDocument::FindFlag> findFlags; -
Hi how do I add
QTextDocument::FindFlagenum to this variable? It only allows me to assign the flags in one time.findFlags = QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords;I want to do it like
if (matchCaseChecked) { findFlags += QTextDocument::FindCaseSensitively; } if (wholeWordsChecked) { findFlags += QTextDocument::FindWholeWords; } -
Hi how do I add
QTextDocument::FindFlagenum to this variable? It only allows me to assign the flags in one time.findFlags = QTextDocument::FindCaseSensitively | QTextDocument::FindWholeWords;I want to do it like
if (matchCaseChecked) { findFlags += QTextDocument::FindCaseSensitively; } if (wholeWordsChecked) { findFlags += QTextDocument::FindWholeWords; } -
@lansing
Hi
You can still just OR them together
if (matchCaseChecked) {
findFlags |= QTextDocument::FindCaseSensitively;
}