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

[SOLVED] arrays?

Scheduled Pinned Locked Moved General and Desktop
16 Posts 5 Posters 16.2k 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.
  • X Offline
    X Offline
    xeroblast
    wrote on last edited by
    #1

    is it possible to have an array like this : arr[int]["string"] = "string"

    i use QVector for arrays : arr[int] = value;
    and QMap for arrays : arr["string"] = value;

    i want to combine this 2 but dont know how.. resulting arr[int]["string"] = "string"

    1 Reply Last reply
    0
    • P Offline
      P Offline
      prajnaranjan.das
      wrote on last edited by
      #2

      Follow this link...I think this may help you...

      http://newdata.box.sk/bx/c/htm/ch11.htm

      Prajnaranjan Das

      e mail: prajnaranjan.das@gmail.com

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vcsala
        wrote on last edited by
        #3

        @QVector<QMap<QString, QString> > arr@, it is important to put space between the two '>'.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xeroblast
          wrote on last edited by
          #4

          already know that... problem is how does this kind of array works in Qt...

          cant use C++ arrays in Qt...

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xeroblast
            wrote on last edited by
            #5

            @VCsala : thanx.. that'll do the trick..

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              In C++, arrays always have indizes. If you want to achieve, what you wrote with
              @
              arr[int][“string”] = “string”
              @

              logically, it would be
              @
              QVector< QMap<QString, QString> > ...
              @

              But the way, you write it, seems like you are coming from something like VB or script languages, not from C/C++?

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vcsala
                wrote on last edited by
                #7

                [quote author="xeroblast" date="1292924751"]cant use C++ arrays in Qt...[/quote]

                You can, but you loose the advantages Qt provides

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  xeroblast
                  wrote on last edited by
                  #8

                  @gerolf: the spaces between the ">" & ">" is my mistake... im into PHP.. just practicing Qt for desktop programming..

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vcsala
                    wrote on last edited by
                    #9

                    [quote author="xeroblast" date="1292925027"]the spaces between the ">" & ">" is my mistake..[/quote]

                    That is really not so straigthforward, you should know that C/C++ has a '>>' operator (which is heavily used in some cases as it is overloaded for stream inputs) to understand this issue.

                    1 Reply Last reply
                    0
                    • X Offline
                      X Offline
                      xeroblast
                      wrote on last edited by
                      #10

                      yeah.. very dumb of me... never comes to my mind... i was so used with PHP and forgot that C++ (or even in Qt) uses this operator...

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        giesbert
                        wrote on last edited by
                        #11

                        bq. xeroblast wrote:
                        cant use C++ arrays in Qt...

                        This is not a C/C++ array: arr[int][“string”]
                        In C/C++ arrays always use indizes.
                        You have a combination of an array (or vector) and a map (mapping of string to value). If you want to achieve that, you have to use the proper classes. In php, you don't decide, whether it's a vector or a map. and perhaps var[int] is a map in php, who knows....

                        Nokia Certified Qt Specialist.
                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          vcsala
                          wrote on last edited by
                          #12

                          Gerolf, is absolutely right, this is not a C++ array as strictly speaking C++ is built on C's array construct which should have always int like indexes. But using C++ object oriented feature, especially operator overloading you can easily achieve that this construct can be used and this is usually provided in several libraries like STL or in our case Qt.

                          1 Reply Last reply
                          0
                          • X Offline
                            X Offline
                            xeroblast
                            wrote on last edited by
                            #13

                            need to review my C/C++..

                            var[any type][any type][any type]... = value; -- is always an array in php

                            any variable can be transform a multidimensional array in php..

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              goetz
                              wrote on last edited by
                              #14

                              Arrays in PHP are actually what maps or associative arraysare in other languages. In PHP the index can be any type, in C/C++ it must be an int (not sure if even an unsigned int) for the builtin types.

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                giesbert
                                wrote on last edited by
                                #15

                                That's what I meant. arrays are C and have a pure numeric (normal numbers, not decimals) index. Everything else is classes (like maps, hashes, sets etc.)

                                Nokia Certified Qt Specialist.
                                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  vcsala
                                  wrote on last edited by
                                  #16

                                  Anyway you can find really good C++ books on "this":http://developer.qt.nokia.com/wiki/Books_and_Links_for_learning_C_and_advanced_topics page (or you can find lots of online references and books, as well). Mastering C++ is almost a lifetime activity.

                                  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