[Qt-interest] "%" characters in QStrings create havoc
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Fri Feb 26 19:00:36 CET 2010
Acutally, now I understand the issue more...
You don't need %%
But on the crash, please provide a minimal reproducible code sample..
What are exp1 and exp2 ?
That said, I wouldn't uses arg substitution for SQL, but I rather use
parameters.. but if you are tring to create the following where clause
WHERE ( name like '%exp1%' ) OR ( email LIKE '%exp2%' )
Then the following code works..
QString cmd = "WHERE ( name like '%%1%' ) OR ( email LIKE '%%2' )"
).arg( "exp1" ).arg( "exp2" );
This code works fine for me with no crash a all..
#include <QCoreApplication>
#include <QString>
#include <QDebug>
int main( int argc, char ** argv )
{
QCoreApplication app(argc, argv);
QString cmd = QString( "WHERE ( name like '%%1%' ) OR ( email LIKE
'%%2%' )" ).arg( "exp1" ).arg( "exp2" );
qDebug() << "cmd=" << cmd;
}
And outputs:
cmd= "WHERE ( name like '%exp1%' ) OR ( email LIKE '%exp2%' )"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100226/0c4f5d40/attachment.html
More information about the Qt-interest-old
mailing list