type qualifiers ignored
-
Hi
I got a "Warnung: type qualifiers ignored on cast result type [-Wignored-qualifiers]"
response.data is unsigned char data[260];
QByteArray ba; Response response = signHash(pin, hash); for (uint i = 0; i < response.length; i++) ba[i] = (const char)response.data[i];
Can i simply remove "(const char)" for same result?
lg Chris
-
Hi
I think it was fixed. I need the QByteArray as Base64 and not the int value;
QByteArray doesn't specify either signed or unsigned sochar ch; unsigned char uch; ch=231; uch=(char) ch; QByteArray ba1, ba2; ba1[0] = ch; ba2[0] = uch; qDebug() << (int)ch << "/"<< (int)uch; qDebug() << ba1 << "/"<< ba2; qDebug() << (signed char)ba1[0] << "/"<< (unsigned char)ba1[0]; qDebug() << (signed char)ba2[0] << "/"<< (unsigned char)ba2[0]; QVERIFY(ba1.toBase64() == ba2.toBase64());
QDEBUG : QRK::testBA() -25 / 231
QDEBUG : QRK::testBA() "\xE7" / "\xE7"
QDEBUG : QRK::testBA() -25 / 231
QDEBUG : QRK::testBA() -25 / 231QVERYFY pass true;
So i can remove (const char)
lg Chris -
What is the data type of response.data ?
-
Hi
response.data is unsigned char data[260];
:)
so issue/warning is unsigned char vs char and
it warns that the cast -removes/ignores the sign.So the big question is about the data.
If it contains negative values, then cast might alter data.
if not, should be fine. -
@mrjj It was miss from my side which is exactly at the the top :)
-
@dheerendra
Funny enough, i also didn't see that line first time i read post. :) -
@ckvsoft I think the problem is the
const
, try to remove it, it serves no purpose here.So either use `append` or search a suitable constructor for ` ba`, like http://doc.qt.io/qt-5/qbytearray.html#QByteArray-1 In that case, you have to `reinterpret_cast< const char *>`
-
@aha_1980 said in type qualifiers ignored:
But: this code will crash as
ba
initially has size zero, so accessing bytes with [] is undefined behavior.it actually won‘t QByeArray atomatically resizes when you try to access it outside it bounds. It‘s slow, but it won‘t crash.
-
@aha_1980 said in type qualifiers ignored:
It's interesting as other Qt containers dont work that way...
'interesting' is imo not the correct word here... it's strange. It's similar to the QContainer::value() functions. :/
-
Hi
I think it was fixed. I need the QByteArray as Base64 and not the int value;
QByteArray doesn't specify either signed or unsigned sochar ch; unsigned char uch; ch=231; uch=(char) ch; QByteArray ba1, ba2; ba1[0] = ch; ba2[0] = uch; qDebug() << (int)ch << "/"<< (int)uch; qDebug() << ba1 << "/"<< ba2; qDebug() << (signed char)ba1[0] << "/"<< (unsigned char)ba1[0]; qDebug() << (signed char)ba2[0] << "/"<< (unsigned char)ba2[0]; QVERIFY(ba1.toBase64() == ba2.toBase64());
QDEBUG : QRK::testBA() -25 / 231
QDEBUG : QRK::testBA() "\xE7" / "\xE7"
QDEBUG : QRK::testBA() -25 / 231
QDEBUG : QRK::testBA() -25 / 231QVERYFY pass true;
So i can remove (const char)
lg Chris -
@ckvsoft said in type qualifiers ignored:
(char)
Just a note: you should avoid C style casts in C++ and use C++ type casts (like static_cast) instead.