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

Reply via email to