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] QList question
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QList question

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

    I'm trying to make a multi-dimensional vector and I am with out a doubt.

    @QList<QString<QString>> CurrPerson;@

    I have a loop and within that loop variable data such as:

    id, name, city, state, country

    I can show the console using the QDebug, but can not create a multi-dimensional vector based on the "id".

    example:

    id = {name, city, state, country}

    1 = {beowulf, my city, my state, my country}
    2 = {youtube, my city, my state, my country}

    And then take the data from this vector by id.

    qDebug () << myvector.id[1]; <- example.

    -- 0x00

    1 Reply Last reply
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      To create a 2 dimension list of strings you need a QList that contains QList's of QString's so the correct syntax will be: QList<QList<QString> > (for old compilers notice the space between > > )

      Anyway from the second part i understand that you might want a struct with: name, city, state, etc members and an associative container like QMap<int, yourStructName> //where int is the id you talk about.

      https://forum.qt.io/category/41/romanian

      1 Reply Last reply
      1
      • B Offline
        B Offline
        beowulf
        wrote on last edited by
        #3

        [quote author="Zlatomir" date="1357906659"]To create a 2 dimension list of strings you need a QList that contains QList's of QString's so the correct syntax will be: QList<QList<QString> > (for old compilers notice the space between > > )

        Anyway from the second part i understand that you might want a struct with: name, city, state, etc members and an associative container like QMap<int, yourStructName> //where int is the id you talk about.[/quote]

        I did not understand your answer.

        My question is one, there is no second part.

        The real question is how to create a multidimensional vector, like this:

        @myvector {
        1 = {beowulf, my city, my state, my country}
        2 = {youtube, my city, my state, my country}
        }@

        -- 0x00

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          There is discussion (development ML) about including QNDArray in a later Qt5 version.

          Zlatomir suggested to create a struct and use it in your container. So:
          @
          struct MyData {
          QString beowulf;
          QString mycity;
          // ... and so on
          }

          // in code:
          QList<MyData>();
          @

          (Z(:^

          1 Reply Last reply
          0
          • ZlatomirZ Offline
            ZlatomirZ Offline
            Zlatomir
            wrote on last edited by
            #5

            The part from id in your first post looked like "second part" to me (as i said i think is a good idea to create a struct/class and use that in a container)

            Anyway if the two dimension list of strings is what you need, that answer is already in my first post: you need QList<QList<QString> >

            https://forum.qt.io/category/41/romanian

            1 Reply Last reply
            0
            • B Offline
              B Offline
              beowulf
              wrote on last edited by
              #6

              Solved. THANKS!

              @QList< QList<QString> > allList;@

              Loop:

              @QList<QString> currLoop;

              currLoop.append(id);

              currLoop.append(name);

              allList.append(currLoop);@

              @void MainWindow::MyTreeWidgetSelected(QTreeWidgetItem *item, int index)
              {

              qDebug() << allList.at(ui->MyTreeWidget->indexOfTopLevelItem(item));
              

              }@

              -- 0x00

              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