Another solution would be moving the call to qprintable inside the prepare_v2 call: sqlite3_prepare_v2( db, qPrintable(qstr) , qstr.length()+1, &stmt, NULL)
I don't know if this is your case but please note that I think this way would not handle well some Unicode strings (the ones for which utf8 and utf16 representation lengths differ) Il 05/set/2014 06:08 "Bob Moran" <bemo...@gmail.com> 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 < > erik.l.nel...@bankofamerica.com> 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 > > sqlite-users@sqlite.org > > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users