Reading QStringList and removing the same



  • Good morning guys,

    I have a StringList formed by a set of information coming from a query, example:
    Each QString formed by "code, ip, location, date"
    "1586; 190.150.60.158; C: \ \ Users \ \ IT; 21/02/2013 15:07:37.848"
    "1611; 190.160.60.158; 168.6.33 \ \ TI2; 21/02/2013 16:05:39.585"
    "1578; 190.168.70.159; C: \ \ Users \ \ IT \ \ Desktop \ ; 02/21/2013 14:57:53.967"
    .
    .
    .

    So I'm trying to go through the list and identify which IPs are repeated, and repeated these, should I just stay with the one that has the greatest code in the list.

    Just an idea of what I'm trying to do now, but without success =)

    @ for (int i = 0; i <removeRepetido.size (); i + +) {
             = removeRepetido.value current (i). split (","). at (1);

    if (current == removeRepetido.value (i +1). split (";"). at (1)) {
                 qDebug () << "will be?" RemoveRepetido.value << (i). Split (";"). At (1) << "CURRENT" << current;
             }
         @}



  • Hi ZergBR!
    Sorry i am not actually understand your goals and your code is not complete. But as i understand you want keep only one item with unique IP which has greatest code. And a simple solution that came to my mind at that time:
    @ QStringList list;
    // load data in to list
    //...
    //
    QMap<QString, int> valueMap;
    foreach (QString str, list) {
    QStringList line = str.split(";",QString::SkipEmptyParts);
    QString key = line.at(1);
    int val = line.at(0).toInt();
    if(valueMap.contains(key))
    {
    if(val > valueMap.value(key))
    {
    valueMap[key] = val;
    }
    }
    else
    {
    valueMap.insert(key, val);
    }
    }@

    at the end in valueMap you will get data you need.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.