[SOLVED] QList question
-
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.
-
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 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}
}@ -
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>();
@ -
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> >
-
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));
}@