[SOLVED]How to store short in a QByteArray?
-
Hi,
I am having a vector of 'short' and i want to convert these 'short' into 'char', so as to be able to store them in a QByteArray.
I am doing these because, i want to playback this data from the output device wich accept only QByteArray.
Please help me to solve this issue.
Thanx in advance.
-
hey i tried this...
@QByteArray ba((const char*)m_output.data(), sizeof(ushort));
playbackBuffer.append(ba);@but i got this error...
error: passing 'const QByteArray' as 'this' argument of 'QByteArray& QByteArray::append(const QByteArray&)' discards qualifiers [-fpermissive]
and one thing my "playbackBuffer" is of type const QByteArray.
-
Ubuntu? add fpermissive to project CFLAGS:
@QMAKE_CXXFLAGS = -fpermissive@
don't forget to run qmake after editing .pro file -
this is not error, it's a warning... calling const instance functions is ok, but dangerous if you don't exactly know what are you doing, thats because gcc warns you about that.
Ubuntu patched gcc has been modified to treat this warning as error... So, you will be just warned with vanilla gcc and compilation will success. It's all on you how to fix this issue... -
so long the “playbackBuffer” is of type const QByteArray, you will getting this warning.
-
I've told you
bq. Ubuntu patched gcc has been modified to treat this warning as error…
add
@QMAKE_CXXFLAGS = -fpermissive@
to project file or redesign your code... -
hey thanx for the precious time u gave for my error...
but i made it work without setting the flag....
like this...
@const QByteArray ba((const char*)m_output.data(), sizeof(ushort));
const_cast<QByteArray &>(playbackBuffer).append(ba);
@thanx once again...
[EDIT: code formatting, Volker]