Just wanted to apologize for the cross/double post.. but, yes, that's right. You need the brackets.
You should consider, using a constructor for your class, which initializes those properties. Or use a struct and plain old c. :->
#include <QApplication>
#include <QDebug>
#include <QList>
class Node
{
public:
int a;
int b;
};
int main(int argc, char *argv[])
{
//case1
QList<int> list1;
list1.append(10);
list1.append(3);
QList<int>::iterator i;
for (i = list1.begin(); i != list1.end(); ++i)
qDebug() << *i;
//case2
QList<Node> list2;
Node no = {11, 12};
list2.append(no);
QList<Node>::iterator j;
for (j = list2.begin(); j != list2.end(); ++j)
{
qDebug() << (*j).a << (*j).b;
}
return 0;
}
#include <QApplication>
#include <QDebug>
#include <QList>
class Node
{
public:
int a;
int b;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//case1
QList<int> list1;
list1.append(10);
list1.append(3);
QList<int>::iterator i;
for (i = list1.begin(); i != list1.end(); ++i)
qDebug() << *i;
//case2
QList<Node> list2;
Node no = {11, 12};
list2.append(no);
QList<Node>::iterator j;
for (j = list2.begin(); j != list2.end(); ++j)
{
qDebug() << (*j).a << (*j).b;
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Johannes
Bookmarks