Cutting Elements QStringlist
Hello friends I have to cut elements before transfer to DB:
My approach is
Code:
int i_fieldlength[]={4,2,4,40,8,6,5,3,8,1,5,3,7,8};
for(int i =0; i < sizeof(i_fieldlength);i++){
QString strbuf
= splitlinelist.
at(i
);
splitlinelist.at(i)=strbuf.left(i_fieldlength[i]);
}
Is there a more elegant way or faster way to do this???
Ups this approach create an error:
Code:
sources\tableeditor.
cpp|
917|error
: passing `
const QString' as `this' argument of `QString
& QString::operator=(const QString
&)' discards qualifiers|
Re: Cutting Elements QStringlist
You can use the database build in functions if your strings aren't too long. MySQL e.g supports
Code:
q.prepare("...SET name = SUBSTRING(:str,0,:len)...");
for(int i =0; i < sizeof(i_fieldlength)/sizeof(i_fieldlength[0]);++i)
{
q.bindValue(":str", splitlinelist.at(i));
q.bindValue(":len", i_fieldlength[i]);
q.exec();
}
NOTE: sizeof(i_fieldlength)/sizeof(i_fieldlength[0]) and ++i!
EDIT: splitlinelist.at(i) => at() is constant so you can't assign a value to that. If you want to use the [] operator.
Re: Cutting Elements QStringlist
I use mssql !
And I do an insert but before I would like to cut the list...
Re: Cutting Elements QStringlist
Quote:
Originally Posted by
Lykurg
EDIT: splitlinelist.at(i) => at() is constant so you can't assign a value to that. If you want to use the [] operator.
Quote:
Originally Posted by
codeman
And I do an insert but before I would like to cut the list...
then use the above mentioned:
Code:
splitlinelist[i] = splitlinelist.at(i).left(i_fieldlength[i]);