[SOLVED] arrays?
-
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"
-
Follow this link...I think this may help you...
-
@QVector<QMap<QString, QString> > arr@, it is important to put space between the two '>'.
-
already know that... problem is how does this kind of array works in Qt...
cant use C++ arrays in Qt...
-
@VCsala : thanx.. that'll do the trick..
-
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++?
-
[quote author="xeroblast" date="1292924751"]cant use C++ arrays in Qt...[/quote]
You can, but you loose the advantages Qt provides
-
@gerolf: the spaces between the ">" & ">" is my mistake... im into PHP.. just practicing Qt for desktop programming..
-
[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.
-
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...
-
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.... -
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.
-
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..
-
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.
-
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.)
-
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.