By using of RegExp, the problem is solved.
For other users who read this question:
My main string is a string of hex (without any space or \x or 0x). I replcae ? in substring by [0-9a-f] and use Qt::CaseInsensitive option:
index = mainString.indexOf(QRegExp(regex,Qt::CaseInsensitive));
QString can handle having an embedded null character (0x00) whereas C strings would treat this a terminator. I can't tell from your screenshot but likely the character where it is truncated is a null byte.
Probably the data is lost when you construct the std::string as constData() returns a pointer to char. You should use the method toStdString() instead.
I am not sure if std::string can contain a null character but I suspect it can.
@RDiGuida To add to @Mario84's answer, QString is Qt based class and your using standard c++ API's to print it which it doesnot understand. To print values of pure Qt based API's you can use qDebug().
From a design point of view it's not ugly. It's actually prettier.
For example if you have a class Triangle or APieceOfRock they have conceptually no debugging or to string conversion notion whatsoever.
Why should a triangle or a piece of rock know anything about strings or how to convert to them? Should it also convert to other data types like ACar or QWidget? Should you add a conversion method to them every time you introduce another type in your app? Making toSting() method in every class is pumping in it functionality that is out of their purpose scope and does not belong to that class.
A separate utility function, detached from the class is actually a much cleaner solution that keeps responsibility separation.
Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.