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. [Solved] QHash and QVector
Qt 6.11 is out! See what's new in the release blog

[Solved] QHash and QVector

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.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.
  • M Offline
    M Offline
    Mike_newbye
    wrote on last edited by
    #1

    Hi,

    I have some data read by lines from a .csv file

    @
    while(!file.atEnd())
    {
    ...
    line = file.readLine();
    list = line.split(',');
    ...
    listSize = list.size();
    @

    I also have to defined a QHash
    @
    QHash<QString, QVector<float> > hash;
    @

    Now I want to store the data read to the hash. I can fill in case if i have @int@ instead of @QVector<float>@. E.g.
    @
    for(int i = 1; i<= listSize; i++)
    {
    hash[QString::number(i)] = 1;
    }
    @

    How to do it with @QVector<float>@ if i want to keep the rows/first element of each row in QVectors.##

    Thanks in advance.

    Kind regards,
    Mikael

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mike_newbye
      wrote on last edited by
      #2

      I solved it myself for filling lines to QVector, can anyone help to do it for rows??

      @while(!file.atEnd())
      {
      line = file.readLine();
      list = line.split(',');
      QVector<float> vec;
      for(int j = 0; j < list.size(); j++)
      {
      vec.push_back(list[j].toFloat());
      }

          hash[line] = vec;
          //qDebug() << list;
      }@
      

      Kind regards,
      Mikael

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        I have some question about your logic:
        Your hash key is the string representation of the QVector content, is that really what you want ?

        What do you mean by rows ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mike_newbye
          wrote on last edited by
          #4

          Hi,

          Thank you for answering.
          Actually I already solved it by myself as follows:

          @for(int j=0; j<listSize; j++)
          {
          hash[headerList[j]].push_back(list[j].toFloat());
          }
          @

          I need this kind of representation as I am doing clustering and I need to separately keep the data from the headers.

          Kind regards,
          Mikael

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You're welcome,

            But still... That logic seems very convoluted...

            If everything is working now, please update the thread's title to solved

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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