zorro68
14th February 2008, 12:32
I am trying to programm a function to get conditions from a registry (particular database), save some registry into lists, and then joint lists with an "or" (list1+list2) condition or "and" (list1-list2). So i get conditions from this functions like this:
select("list i want to return", "condition1==something", "and or or", "condition2==somthing", "and or or",..........)
the code is this:
QStringList COMMANDS::select(QString key,...)
{
QList<QString> list;
QStringList conditions;
QMultiMap<QString,QString>keyvalue;
va_list p;
va_start(p,key);
char *arg;
int cont=0;
int ncondition=0;
while ((arg=va_arg(p,char *))){
if(toQString(arg)=="")break;
cont++;
int cnd=cont%2;
if (cnd==1){
QStringList kv=toQString(arg).split("==");
keyvalue.insert(kv[0].trimmed(),kv[1].trimmed());
}else if (cnd==0){
conditions.push_back(toQString(arg));
ncondition++;
}
}
va_end(p);
QVector <QStringList> lists;
QMapIterator<QString, QString> m(keyvalue);
if(cont==0){
for(int i=0;i<data.size();i++)
list+=getValues(key,data[i]);
}else{
for(int i=0;i<data.size();i++){
if(ExistKey(key,data[i])){
m.toFront();
while (m.hasNext()) {
m.next();
if(ExistValue(m.key(),m.value(),data[i]))
lists.append(getValues(key,data[i]));
}
/*m.toBack();
while (m.hasPrevious()){
m.previous();
QString v=m.value();
if(ExistValue(m.key(),m.value(),data[i]))
lists.append(getValues(key,data[i]));
}*/
}
}
}
for (int i=0;i<lists.count();i++)
if(i==0)
list=lists[0];
else
list=QSlogical(list,lists[i],conditions[i-1]);
return list;
}
In keyvalue.insert (line 19) i save condition==something in a QMap in the correct order, but when i read with the QMapIterator and save into lists vector (line 36-40), list[0] correspond to the last condition==something, list[1] correspond to first condition, list[2] second conditions,....
The correct order would be:
condition1 ---> list[0]
condition2 ---> list[1]
......
And this is a bad behaviour formy programm because logical values are not commutavive:
l1 and l2 or l3 is not equal to l1 or l2 and l3 (l1,l2,l3 are qstringlist)
I expect you understand wich is my problemm.
Anybody know what happend with QMapIterator? or Is this a extrage behaviour of QMapIterator? or Is my code bad?
select("list i want to return", "condition1==something", "and or or", "condition2==somthing", "and or or",..........)
the code is this:
QStringList COMMANDS::select(QString key,...)
{
QList<QString> list;
QStringList conditions;
QMultiMap<QString,QString>keyvalue;
va_list p;
va_start(p,key);
char *arg;
int cont=0;
int ncondition=0;
while ((arg=va_arg(p,char *))){
if(toQString(arg)=="")break;
cont++;
int cnd=cont%2;
if (cnd==1){
QStringList kv=toQString(arg).split("==");
keyvalue.insert(kv[0].trimmed(),kv[1].trimmed());
}else if (cnd==0){
conditions.push_back(toQString(arg));
ncondition++;
}
}
va_end(p);
QVector <QStringList> lists;
QMapIterator<QString, QString> m(keyvalue);
if(cont==0){
for(int i=0;i<data.size();i++)
list+=getValues(key,data[i]);
}else{
for(int i=0;i<data.size();i++){
if(ExistKey(key,data[i])){
m.toFront();
while (m.hasNext()) {
m.next();
if(ExistValue(m.key(),m.value(),data[i]))
lists.append(getValues(key,data[i]));
}
/*m.toBack();
while (m.hasPrevious()){
m.previous();
QString v=m.value();
if(ExistValue(m.key(),m.value(),data[i]))
lists.append(getValues(key,data[i]));
}*/
}
}
}
for (int i=0;i<lists.count();i++)
if(i==0)
list=lists[0];
else
list=QSlogical(list,lists[i],conditions[i-1]);
return list;
}
In keyvalue.insert (line 19) i save condition==something in a QMap in the correct order, but when i read with the QMapIterator and save into lists vector (line 36-40), list[0] correspond to the last condition==something, list[1] correspond to first condition, list[2] second conditions,....
The correct order would be:
condition1 ---> list[0]
condition2 ---> list[1]
......
And this is a bad behaviour formy programm because logical values are not commutavive:
l1 and l2 or l3 is not equal to l1 or l2 and l3 (l1,l2,l3 are qstringlist)
I expect you understand wich is my problemm.
Anybody know what happend with QMapIterator? or Is this a extrage behaviour of QMapIterator? or Is my code bad?