Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Txt file data to Qmap

    General and Desktop
    3
    6
    1481
    Loading More Posts
    • 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.
    • Chandras002
      Chandras002 last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 3
        • Chandras002
          Chandras002 last edited by

          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
          
          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @Chandras002 last edited by

            @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?

            Chandras002 1 Reply Last reply Reply Quote 2
            • Chandras002
              Chandras002 @mrjj last edited by

              @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

              jsulm 1 Reply Last reply Reply Quote 0
              • jsulm
                jsulm Lifetime Qt Champion @Chandras002 last edited by

                @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 Reply Quote 2
                • First post
                  Last post