i'm trying wrap libssh2 in qt, , have following code:
const char* username = inusername.tolocal8bit().data(); const char* password = inpass.tolocal8bit().data();
problem is, username , password doesn't connect system. why?
because, according debugger,
username "5.1p1 debian-6ubuntu2" password "5.1p1 debian-6ubuntu2"
those not values i've given username or password. i've tried toascii, tolatin1, , appending (or not) .data(). still, these values, instead of expected values. i'm on windows, why it's more troubling, since, far can tell, nothing have compiled on debian or ubuntu.
what's going on here?
this code:
const char* username = inusername.tolocal8bit().data();
is equivalent this:
const char * username; { const qbytearray l8b = inusername.tolocal8bit(); username = l8b.data(); }
do see what's going on? time statement has executed, temporary qbytearray
has been deleted compiler again. since data()
returns pointer internal qbytearray
buffer, username
points deleted/freed memory.
to solve problem, make username
, password
qbytearray
s instead of const char*
s, , use username.data()
, password.data()
instead used username
, password
before.
Comments
Post a Comment