Comparing QString and char*
I am trying to compare QString against char*, but I fail to do that:
Code:
void Register::checkKey()
{
QFile kFile
("license.key");
{
sd.setText("The registration key doesn't exist.\n");
sd.exec();
exit(0);
}
kFile.close();
char ser[22];
hdidnt(ser);
char *crypt = hash.toUtf8().data();
encrypt(crypt, "key");
MD5 md;
if (test
!= QString::fromUtf8(md.
digestString(md.
digestString(md.
digestString(crypt
))))) {
sdf.
setText(QString::fromUtf8(md.
digestString(md.
digestString(md.
digestString(crypt
)))) + "\n" \
+ test + "\n" \
+ QString::number(sizeof(test.
toUtf8())) + "\n" \
);
sdf.exec();
sd.setText("This product must have a valid key.\n");
sd.exec();
KeyDialog kDialog;
kDialog.
setKey(QString::fromUtf8(md.
digestString(crypt
)));
kDialog.exec();
exit(0);
}
}
I tryied also to convert QString to char* then make the comparison but I fail too. Both QString test and md.digestString(md.digestString(md.digestString(cr ypt))) return some value but they unenable to compare.
Re: Comparing QString and char*
I would write something like this ...
Code:
char *crypt = cryptByteArray.data();
If you write directly
Code:
char *crypt = hash.toUtf8().data();
then temporary QByteArray will no longer exists and "crypt" will point to dangled pointer.
Re: Comparing QString and char*
Be sure to discard the newline character in case there is one in the file.
Re: Comparing QString and char*
Thenks Mr cincirin, it works now.