Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Reading QStringList and removing the same
Qt 6.11 is out! See what's new in the release blog

Reading QStringList and removing the same

Scheduled Pinned Locked Moved Qt Creator and other tools
2 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    ZergBR
    wrote on last edited by
    #1

    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;
             }
         @}

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved