Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved] Comparing QString and QByteArray
Hello everyone, I have a problem comparing Qstring and Qbytearray data, Can anyone help me with this please.!!
if (readData.contains(str_id[i].toUtf8())) //This is the part of code where my error exists.
no matching function for call to 'QByteArray::contains(QString&)'
What is 'i' there in str_id[i].toUtf8() ? Just try with this. Based on this you can fix the issue.
@ QStringList list;
list<< "1 "<<"2";
Sorry Dheerendra this is my actual line
Below are the values present in Qtstringlist
str_id.at(1) = 2103
str_id.at(2) = 2204
str_id.at(3) = 2296
str_id.at(4) = 7485
str_id.at(5) = 9375
and readData is a QByteArray which consists of one of the following at a time
@"ID : 2013 Heart Beat : 72 Movement : yes"
"ID : 2048 Heart Beat : 75 Movement : yes"
"ID : 2169 Heart Beat : 73 Movement : yes"
"ID : 2204 Heart Beat : 72 Movement : yes"@
So I have to compare the qstringlist element each at a time with the Qbytearray data, i have written for loop for doing this hence 'i' variable is used like below,
//Do Some Operation
//Do Some Operation
and n is the Qstringlist size which is calculated through size function i.e "str_id.size()"
Can you help me out with the compare function please.!!
The following is the actual scenario which I have to do with this code,
@readData = "ID : 2013 Heart Beat : 72 Movement : yes"
str_id.at(1) = 2013@
comparing these qbytearray and qstring data the above mentioned if condition should return true.
Not sure why are converting data to QByteArray. I remember you are reading data from file and making it ByteArray. I feel which converting to ByteArray is not required.
You can try something like this.
@ QByteArray readData = "ID : 2013 Heart Beat : 72 Movement : yes";
qDebug() << readData.data() << " He ="<<readData;
QByteArray dat = "2013";
QString data1= "2013";
qDebug() << "What man "<<endl;
qDebug() << "No man"<<endl;
Thanks for your simple sample code Dheerendra. It worked and I modified my project code with it. Thanks a lot once again. :)
You can put this question to SOLVED state.