Похожие чаты

Qt/C++ question, how can i remove warnings on this function?

its to sort files comparing numbers if they exist (the files are roughly in the same format, but sometimes they don't have 0-padding), i want file2 before file10, and file2-2 before file2-10

bool compare(const QString &v1, const QString &v2) {
QRegularExpression r("(\\d+)");
auto match1 = r.globalMatch(v1);
auto match2 = r.globalMatch(v2);
while (match1.hasNext() && match2.hasNext()) {
int num1 = match1.next().captured(1).toInt();
int num2 = match2.next().captured(1).toInt();
if (num1 != num2) {
return (num1 < num2);
}
}
return v1 < v2;
}
called from std::sort :
//fileList is a QStringList
std::sort(fileList.begin(), fileList.end(), compare);

The warning is
Don't create temporary QRegularExpression objects. Use a static QRegularExpression object instead [clazy-use-static-qregularexpression] on both lines starting with auto match...

edit: the function does what i want, but i wanna remove the warning

2 ответов

25 просмотров

Did you try "not creating temporary QRegularExpression objects. Use a static QRegularExpression object instead"? Every time you call compare you're creating new class for no reason.

E- Автор вопроса
Ihor
Did you try "not creating temporary QRegularExpres...

How can i not create it? Don't i need a new match every compare? Unless it means QRegularExpression r needs to be static, but the warning shows on match1 and match2 which are QRegularExpressionMatchIterator

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта