[Qt-interest] Strange (as for me) QByteArray behavior
Marek Bronowicki
marek at cyberdeus.pl
Wed Dec 8 07:13:42 CET 2010
Hello
I'm developing a sip softphone based on pjsip.
I noticed a strange behavior converting QByteArray to char *.
there is a function in pjsip named pj_str(char *)
I need a username from config so I'm doing a simple thing:
--- 1 ---
QString username = config.username; // config.username is a QString
pjsua_acc_config acc;
acc.cred_info[0].username = pj_str(username.toAscii().data());
--- 1 ---
and according to doc
http://doc.trolltech.com/latest/qbytearray.html#data in my opinion it
should work, but it doesn't.
After some websearch I found to do:
--- 2 ---
QString username = config.username; // config.username is a QString
QByteArray tmp = username.toAscii();
char *ptr = tmp.data();
pjsua_acc_config acc;
acc.cred_info[0].username = pj_str(ptr);
--- 2 ---
and this is working properly.
So my question is what is the difference between solution 1 and 2? I
didn't noticed the difference of strings for example in qDebug() << ptr
and qDebug() << username.toAscii().data(), so I'm really confused.
Regards,
Marek Bronowicki
More information about the Qt-interest-old
mailing list