Results 1 to 3 of 3

Thread: bad behaviour of QMapIterator

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default bad behaviour of QMapIterator

    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:

    Qt Code:
    1. QStringList COMMANDS::select(QString key,...)
    2. {
    3. QList<QString> list;
    4. QStringList conditions;
    5. QMultiMap<QString,QString>keyvalue;
    6.  
    7. va_list p;
    8. va_start(p,key);
    9. char *arg;
    10.  
    11. int cont=0;
    12. int ncondition=0;
    13. while ((arg=va_arg(p,char *))){
    14. if(toQString(arg)=="")break;
    15. cont++;
    16. int cnd=cont%2;
    17. if (cnd==1){
    18. QStringList kv=toQString(arg).split("==");
    19. keyvalue.insert(kv[0].trimmed(),kv[1].trimmed());
    20. }else if (cnd==0){
    21. conditions.push_back(toQString(arg));
    22. ncondition++;
    23. }
    24. }
    25. va_end(p);
    26.  
    27. QVector <QStringList> lists;
    28.  
    29. QMapIterator<QString, QString> m(keyvalue);
    30. if(cont==0){
    31. for(int i=0;i<data.size();i++)
    32. list+=getValues(key,data[i]);
    33. }else{
    34. for(int i=0;i<data.size();i++){
    35. if(ExistKey(key,data[i])){
    36. m.toFront();
    37. while (m.hasNext()) {
    38. m.next();
    39. if(ExistValue(m.key(),m.value(),data[i]))
    40. lists.append(getValues(key,data[i]));
    41. }
    42. /*m.toBack();
    43. while (m.hasPrevious()){
    44. m.previous();
    45. QString v=m.value();
    46. if(ExistValue(m.key(),m.value(),data[i]))
    47. lists.append(getValues(key,data[i]));
    48. }*/
    49. }
    50. }
    51. }
    52.  
    53. for (int i=0;i<lists.count();i++)
    54. if(i==0)
    55. list=lists[0];
    56. else
    57. list=QSlogical(list,lists[i],conditions[i-1]);
    58.  
    59. return list;
    60. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: bad behaviour of QMapIterator

    Sorry, the problem is another (line 40)

    Thanks

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: bad behaviour of QMapIterator

    You shouldn't use QMultiMap here, because you loose the order of conditions. Use a list of pairs instead.

Similar Threads

  1. Disable default tab behaviour for a QGraphicsItem
    By nmather in forum Qt Programming
    Replies: 3
    Last Post: 13th December 2017, 11:30
  2. Managing widget focus behaviour
    By mnemonic_fx in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2008, 11:27
  3. QAbstractItemView selection behaviour issue
    By Caius Aérobus in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2007, 17:33
  4. Different behaviour on different distributions
    By Kumula in forum Qt Programming
    Replies: 17
    Last Post: 7th March 2006, 00:58
  5. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 07:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.