want to convert a QString to GBytes (glib)
I tried the following by converting the QString to GByteArray and than freeing it to GBytes
extern "C" {
#include <glib.h>
};
#include <QString>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QString mylongstring = "HELLO_WORLD";
GByteArray *barr;
barr = g_byte_array_new ();
for (int i = 0; i < mylongstring.toLocal8Bit().count(); i++)
{
guint8 *charAt = (guint8*)mylongstring.at(i); //cant convert qchar to uint -> already crashes
g_byte_array_append (barr, (guint8*) charAt, 1);
}
GBytes *gbytes = g_byte_array_free_to_bytes(barr); //should contain the (guint8*) data of mylongstring
return app.exec();
}