--===============0019531629== Content-Type: multipart/signed; boundary="nextPart1886727.p1lTdDL8Ea"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart1886727.p1lTdDL8Ea Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Sunday 02 October 2005 21:58, Roberto Cappuccio wrote: > I don't know why it does not work with sqlite3. > If I pass directly myStr.utf().data(), it saves garbage. > If I copy the stuff in a newly created char* it works fine. This is the > code that works: > > QString qsValue =3D "=E3=82=B9=E3=83=9D=E3=83=BC=E3=83=84"; > > int len =3D qsValue.utf8().length(); > char* cUTF8 =3D new char[ len + 1 ]; > memcpy( cUTF8, qsValue.utf8().data(), len ); > cUTF8[ len ]=3D '\0'; > int nRes =3D sqlite3_bind_text( mpVM, nParam, cUTF8, -1, SQLITE_STATI= C ); > > This is the code that doesn't work: > > int len =3D qsValue.utf8().length(); > int nRes =3D sqlite3_bind_text( mpVM, nParam, > (const char*)qsValue.utf8().data(), -1, SQLITE_STATIC ); > > I really don't understand why the second way does not work for me. > > Thanks I don't know how SQLite uses the string but QString.data() is only valid as= =20 long as the QString is not destroyed. And it is no longer valid if you do a= ny=20 operation on the string. If the sqlite call just keeps a pointer to your=20 string, which is flushed only on a commit, the data pointer will no longer = be=20 valid. The char* cUTF8 =3D new char[ len + 1 ]; line ensures the data is=20 preserved. Luciano =2D-=20 Luciano Montanaro // \X/ mikelima@cirulla.net --nextPart1886727.p1lTdDL8Ea Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQBDQFT8aeOY6B53J4URAjfaAJ4vFXzFctSwMGUxFTzyDBoroa021gCcCPJc 1JWIUA0KwBK5Iw1nXJ6DctI= =JeBv -----END PGP SIGNATURE----- --nextPart1886727.p1lTdDL8Ea-- --===============0019531629== Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline = >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscrib= e << --===============0019531629==--