You could use QString::constData which returns a pointer to internal data to the string encoded in utf16 and then change the call to sqlite3_prepare16_v2... Il 05/set/2014 06:08 "Bob Moran" <[email protected]> ha scritto:
> Erik, > Are you implying that I must copy the text returned by qPrintable(sql) to a > safe location before calling a method that uses it? I thought that the > string would be valid until I return from the routine. > > Bob Moran > > > On Wed, Sep 3, 2014 at 1:29 PM, Nelson, Erik - 2 < > [email protected]> wrote: > > > Bob Moran wrote on Wednesday, September 03, 2014 12:45 PM > > > > > > One added note: My GUI is using QT4, where in this case the SQL text > > > goes something like: > > > > > > QString qstr = "select id, step, temp from protocols where id > > > = %1"; > > > qstr = qstr.arg(id); > > > char * str = (char*)qPrintable(qstr); > > > sqlite3_prepare_v2( db, str, qstr.Length+1, &stmt, NULL) > > > > > > > That's pretty different than the pseudocode you presented earlier. > > > > From the docs for qPrintable > > http://qt-project.org/doc/qt-4.8/qtglobal.html#qPrintable > > > > ********************** > > Returns str as a const char *. This is equivalent to > > str.toLocal8Bit().constData(). > > > > The char pointer will be invalid after the statement in which > qPrintable() > > is used. This is because the array returned by toLocal8Bit() will fall > out > > of scope. > > **************************** > > > > Your str is likely pointing to memory that has been freed? > > > > Erik > > > > ---------------------------------------------------------------------- > > This message, and any attachments, is for the intended recipient(s) only, > > may contain information that is privileged, confidential and/or > proprietary > > and subject to important terms and conditions available at > > http://www.bankofamerica.com/emaildisclaimer. If you are not the > > intended recipient, please delete this message. > > _______________________________________________ > > sqlite-users mailing list > > [email protected] > > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > > _______________________________________________ > sqlite-users mailing list > [email protected] > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

