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. QVector various data format
Qt 6.11 is out! See what's new in the release blog

QVector various data format

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 3.7k Views 2 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.
  • jipe3001J Offline
    jipe3001J Offline
    jipe3001
    wrote on last edited by
    #1

    I am wandering if I can use a multi dimensions QVector to store data with different format

    Of course the QVector<QVector<QString> > is working but only for a same data format
    ( QString in this example)

    Is there a way to define several data format (one per dimension) within the same Qvector ?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi, and welcome to the Qt forum! How about using QVariant?

      jipe3001J 1 Reply Last reply
      0
      • ? A Former User

        Hi, and welcome to the Qt forum! How about using QVariant?

        jipe3001J Offline
        jipe3001J Offline
        jipe3001
        wrote on last edited by
        #3

        @Wieland

        Thks for your help, that's really what I was looking for.
        However I have another question regarding a QVector multi dimensions structure.

        For instance a structure declared like this:

        QVector< QVector< QVector< QVariant > > > test_vector_3d;
        QVector< QVector< QVariant > > test_vector_2d;
        QVector< QVariant > test_vector_1d;

        QVariant qv1="item1";
        QVariant qv2="item2";
        QVariant qv3="item3";

        test_vector_1d.append(qv1);
        test_vector_1d.append(qv2);

        test_vector_2d.append(test_vector_1d);

        How can I append a third QVariant (qv3) to the test_vector_3d ?

        Thks in advance

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          QVector< QVector< QVector< QVariant > > > is a vector of vectors of vectors of variants ie a 3D "cube" of QVariants.
          What's the expected result i.e. to which dimension do you want the value appended? Because there's no one answer to this question. In other words which of the 8 corners of the cube should expand?

          1 Reply Last reply
          0
          • jipe3001J Offline
            jipe3001J Offline
            jipe3001
            wrote on last edited by
            #5

            In my example only test_vector _2d is filled with values eg: test_vector_2d [item2] [item1]

            My question is about how to load a value [item3] for the 3rd dimension
            test_vector_3d [??] [item2] [item1]

            It should be something like this:
            test_vector_3d.append(test_vector_2d);

            but I can't figure out how to append the QVariant qv3 to this array

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by Chris Kawa
              #6

              @jipe3001 said:

              test_vector_3d [??] [item2] [item1]

              item1 and item2 are not indices so that's not what you have in your example. What you have is:

              test_vector_1d[0] == item1
              test_vector_1d[1] == item2
              
              test_vector_2d[0][0] == item1
              test_vector_2d[0][1] == item2
              

              So again, what's your desired result. Any of these?

              test_vector_3d[0][0][0] == item3
              test_vector_3d[0][0][1] == item3
              test_vector_3d[0][1][0] == item3
              test_vector_3d[1][0][0] == item3
              test_vector_3d[0][1][1] == item3
              test_vector_3d[1][1][0] == item3
              test_vector_3d[1][0][1] == item3
              test_vector_3d[1][1][1] == item3
              
              1 Reply Last reply
              0
              • jipe3001J Offline
                jipe3001J Offline
                jipe3001
                wrote on last edited by
                #7

                You are right I did not mean item x was an index but the value in the cell, my mistake !

                Here is a screen shot of a debug session, showing the 1d,2d, 3d vectors after being initialize with append as described in my previous msg.

                	v_records_1d	<3 éléments>	QVector<QVariant>
                		[0]	(int) 1	QVariant
                			d	struct QVariant::Private	QVariant::Private
                				data	union QVariant::Private::Data	union QVariant::Private::Data
                				type	2	unsigned int
                				is_shared	0	unsigned int
                				is_null	0	unsigned int
                		[1]	(int) 9869	QVariant
                		[2]	(double) 16.140000000000001	QVariant
                	v_records_2d	<1 élément>	QVector<QVector<QVariant>>
                		[0]	<3 éléments>	QVector<QVariant>
                			[0]	(int) 1	QVariant
                			[1]	(int) 9869	QVariant
                			[2]	(double) 16.140000000000001	QVariant
                	v_records_3d	<1 élément>	QVector<QVector<QVector<QVariant>>>
                		[0]	<1 élément>	QVector<QVector<QVariant>>
                			[0]	<3 éléments>	QVector<QVariant>
                				[0]	(int) 1	QVariant
                				[1]	(int) 9869	QVariant
                				[2]	(double) 16.140000000000001	QVariant
                

                We can see that
                test_vector_3d[0][0][0] = 1
                test_vector_3d[0][0][1] = 9869
                test_vector_3d[0][0][2] = 16.14

                My question is how can I enter values using append method for

                test_vector_3d[0][1][0]
                test_vector_3d[0][1][1]
                test_vector_3d[0][1][2]

                and

                test_vector_3d[1][1][0]
                test_vector_3d[1][1][1]
                test_vector_3d[1][1][2]

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  To put something in item indexed [1] there's gotta be item [0] first, so to get

                  test_vector_3d[0][1][0]
                  test_vector_3d[0][1][1]
                  test_vector_3d[0][1][2]
                  

                  you'd do:

                  QVector<QVariant> test_vector_1d;
                  test_vector_1d.append(1);
                  test_vector_1d.append(9869);
                  test_vector_1d.append(16.14);
                  
                  QVector<QVector<QVariant>> test_vector_2d;
                  test_vector_2d.append(QVector<QVariant>()); //that's index [0]
                  test_vector_2d.append(test_vector_1d);      //that's index [1]
                  
                  QVector<QVector<QVector<QVariant>>> test_vector_3d;
                  test_vector_3d.append(test_vector_2d);
                  

                  Similarly, to get

                  test_vector_3d[1][1][0]
                  test_vector_3d[1][1][1]
                  test_vector_3d[1][1][2]
                  

                  you'd do:

                  QVector<QVariant> test_vector_1d;
                  test_vector_1d.append(1);
                  test_vector_1d.append(9869);
                  test_vector_1d.append(16.14);
                  
                  QVector<QVector<QVariant>> test_vector_2d;
                  test_vector_2d.append(QVector<QVariant>()); //that's index [0]
                  test_vector_2d.append(test_vector_1d);      //that's index [1]
                  
                  QVector<QVector<QVector<QVariant>>> test_vector_3d;
                  test_vector_3d.append(QVector<QVector<QVariant>>()); //that's index [0]
                  test_vector_3d.append(test_vector_2d);               //that's index [1]
                  
                  jipe3001J 1 Reply Last reply
                  1
                  • Chris KawaC Chris Kawa

                    To put something in item indexed [1] there's gotta be item [0] first, so to get

                    test_vector_3d[0][1][0]
                    test_vector_3d[0][1][1]
                    test_vector_3d[0][1][2]
                    

                    you'd do:

                    QVector<QVariant> test_vector_1d;
                    test_vector_1d.append(1);
                    test_vector_1d.append(9869);
                    test_vector_1d.append(16.14);
                    
                    QVector<QVector<QVariant>> test_vector_2d;
                    test_vector_2d.append(QVector<QVariant>()); //that's index [0]
                    test_vector_2d.append(test_vector_1d);      //that's index [1]
                    
                    QVector<QVector<QVector<QVariant>>> test_vector_3d;
                    test_vector_3d.append(test_vector_2d);
                    

                    Similarly, to get

                    test_vector_3d[1][1][0]
                    test_vector_3d[1][1][1]
                    test_vector_3d[1][1][2]
                    

                    you'd do:

                    QVector<QVariant> test_vector_1d;
                    test_vector_1d.append(1);
                    test_vector_1d.append(9869);
                    test_vector_1d.append(16.14);
                    
                    QVector<QVector<QVariant>> test_vector_2d;
                    test_vector_2d.append(QVector<QVariant>()); //that's index [0]
                    test_vector_2d.append(test_vector_1d);      //that's index [1]
                    
                    QVector<QVector<QVector<QVariant>>> test_vector_3d;
                    test_vector_3d.append(QVector<QVector<QVariant>>()); //that's index [0]
                    test_vector_3d.append(test_vector_2d);               //that's index [1]
                    
                    jipe3001J Offline
                    jipe3001J Offline
                    jipe3001
                    wrote on last edited by
                    #9

                    @Chris-Kawa

                    That's very clear now.

                    Thanks for your quick answers

                    I really appreciated your help

                    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