Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Txt file data to Qmap
Forum Updated to NodeBB v4.3 + New Features

Txt file data to Qmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.8k 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.
  • Chandras002C Offline
    Chandras002C Offline
    Chandras002
    wrote on last edited by
    #1

    Dear Qt friends, I am try to read txt file info to QMap as following code.
    The text file has IP info separated by new line,
    Name: IP info
    IP address :10.1.1.10
    Port: 8888
    the lst output is ("Name:IP info", ..... ," ")
    on the Qmap insert getting error "no matching function for call to
    'QMap<long long int, QString>::value(const QString&)'

    Am i miss something, i saw many similar error posted on forum but as get how to solve this (i an new to Qt) . Any thoughts/ suggestion highly useful.

    void Save()
    {
        int c = -1;
        QFile inputFile("C:\\Users\\IP_info.txt");
        QMap<qint64,QString> map;
      
    
        if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            qDebug()<<"Could not open input file";
            return;
    
         }
        while (!inputFile.atEnd())
        {
               const QByteArray alldata = inputFile.readAll();
               const QString str(alldata);
               const QStringList lst = QString(alldata).split('\n');
    
               qDebug()<<lst;
              // const QString str(line);
              // const QStringList lst = line.split('\n');
    
               for (int i=0; i<lst.size(); i++)
                {
                   if (!map.value(lst.at(i)))  //getting error 
                 //    if (!map.containslst.at(i))) 
                    {
                        map.insert(lst.at(i),++c);
                    }
                }
               qDebug() << map;
                inputFile.close();
            }
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi
      Your map is
      QMap<qint64, QString>
      So int as key, and string as value.

      and you try to call so
      http://doc.qt.io/qt-5/qmap.html#value
      !map.value( lst.at(i) )
      but is lst.at(i) not a string and your key is qint64 ?
      So should it not be
      http://doc.qt.io/qt-5/qmap.html#contains
      if you try checking if u already have key ?
      also, is
      lst.at(i) ment to be the qint64? but just as text ?

      else it seems a bit reverse to me.

      1 Reply Last reply
      3
      • Chandras002C Offline
        Chandras002C Offline
        Chandras002
        wrote on last edited by
        #3

        yes, you are right it was reversed. The following code store values in QMap. now i want the QMap key, String (value) into a another txt file. (Copy_IP_Info. txt) After written into new txt file (Copy_IP_Info) , the program objective

        1. have to check in certain interval of original IP_Info.txt
        2. If any info (value) changed in original file like IP address changed but Port number is same then only IP address should be updated to copy_IP_info file.

        Is it too complex? STL containers are new to me.. am i miss anything.. .any suggestion highly useful.

        
         for (int i=0; i<lst.size(); i++)
                    {
        
        
                      // if (!map.value(lst.at(i)))
                        {
                            map.insert(++c,lst.at(i));
                        }
        
                    }
        
        QMap((0, "Name:Follower2")(1, "IP_address:192.168.27.38")(2, "PORT_number:88888")(3, "Time_stamp:25th June 2018:3.00am")(4, "Version:1.0")(5, ""))
        r code here
        
        mrjjM 1 Reply Last reply
        0
        • Chandras002C Chandras002

          yes, you are right it was reversed. The following code store values in QMap. now i want the QMap key, String (value) into a another txt file. (Copy_IP_Info. txt) After written into new txt file (Copy_IP_Info) , the program objective

          1. have to check in certain interval of original IP_Info.txt
          2. If any info (value) changed in original file like IP address changed but Port number is same then only IP address should be updated to copy_IP_info file.

          Is it too complex? STL containers are new to me.. am i miss anything.. .any suggestion highly useful.

          
           for (int i=0; i<lst.size(); i++)
                      {
          
          
                        // if (!map.value(lst.at(i)))
                          {
                              map.insert(++c,lst.at(i));
                          }
          
                      }
          
          QMap((0, "Name:Follower2")(1, "IP_address:192.168.27.38")(2, "PORT_number:88888")(3, "Time_stamp:25th June 2018:3.00am")(4, "Version:1.0")(5, ""))
          r code here
          
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Chandras002
          But its not really possible to update in the middle of a text file without rewriting the whole file.
          so unless its sort of a binary fixed record file, you will have to write the other data too.
          Im not really sure in what way Copy_IP_Info is different original IP_Info.txt
          except maybe its other format?

          Chandras002C 1 Reply Last reply
          2
          • mrjjM mrjj

            @Chandras002
            But its not really possible to update in the middle of a text file without rewriting the whole file.
            so unless its sort of a binary fixed record file, you will have to write the other data too.
            Im not really sure in what way Copy_IP_Info is different original IP_Info.txt
            except maybe its other format?

            Chandras002C Offline
            Chandras002C Offline
            Chandras002
            wrote on last edited by
            #5

            @mrjj : Hi, I got your point. Can not update the particular string... have to write whole file. Copy_IP_info.txt can be LOG file.
            In case, i want to append the latest data from IP_Info.txt for every 10 min with time stamp.. So, know the connection status details. Any thoughts?
            Thanks,

            Cheers!
            chandra

            jsulmJ 1 Reply Last reply
            0
            • Chandras002C Chandras002

              @mrjj : Hi, I got your point. Can not update the particular string... have to write whole file. Copy_IP_info.txt can be LOG file.
              In case, i want to append the latest data from IP_Info.txt for every 10 min with time stamp.. So, know the connection status details. Any thoughts?
              Thanks,

              Cheers!
              chandra

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Chandras002 If you want to append at the end of the file then there is no need to overwrite the whole file, just open it in append mode.

              file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
              

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2

              • Login

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