Hi everyone, I'm new to this forum (but not to QT programming).
I'm facing this problem: I wanto to check if a particular string is contained in another string. If I do:
QString temp
= "hello world, hello every one";
bool a = temp.contains("hello world");
//now bool is true
QString temp = "hello world, hello every one";
bool a = temp.contains("hello world");
//now bool is true
To copy to clipboard, switch view to plain text mode
If I do:
QString temp
= "hello world, hello every one";
bool a = temp.contains(match);
//bool is ALWAYS false
QString temp = "hello world, hello every one";
QString match = "hello world";
bool a = temp.contains(match);
//bool is ALWAYS false
To copy to clipboard, switch view to plain text mode
It seems that QString::contains() or QString::startsWith() and so on work only with string literals. Same results if I try to create a QRegExp. If I create it with a string literal it works, otherwise it doesn't. Same thing with QStringMatcher.
Any suggestion on how to avoid a string search char by char? Is it normal that such an important QT module works only with literals?
Thanks,
ShaoLin
Added after 38 minutes:
Solved using:
(temp.toStdString().find(biggerFile.toStdString()) >= 0)
(temp.toStdString().find(biggerFile.toStdString()) >= 0)
To copy to clipboard, switch view to plain text mode
that is standard c++ string pattern matching. Anyway, is there a QT solution for this kind of problem?
Thx,
ShaoLin
Bookmarks