Solved how to add children to the QTree Widget
-
@mrjj said in how to add children to the QTree Widget:
but
if i give
int i = m_data.size();
and print the i value , I can see the data size that which i have inserted in the list.But if i try to see the data
QString H = m_data.at(i);
and print the H value using qDebug i data is not coming and the application crashes -
@ManiRon
Yes, you access to high index.
as u start with 1.
and list start with zero.
So that can crash. -
This post is deleted! -
@mrjj but my size is two. I have inserted two data and i am trying to see the second data then it should work right?
-
@ManiRon OK SIR IT WORKED
-
I have another doubt sir
-
@ManiRon
super :)
ask away :) -
How to use this ? for this only i am trying
-
@mrjj What is my doubt is i want to add N number of children to a toplevelitem and one child to each child ? How can i add N Number of childern first
-
@ManiRon
Its a list of QTreeWidgetItems * ( pointers)
So you must add them to a QList then give QList to tree.
Its just a function to add multiple items at once.// top one QTreeWidgetItem *treeItemROOT = new QTreeWidgetItem(ui->treeWidget); treeItem->setText(0, name); treeItem->setText(1, description); // first child QTreeWidgetItem *treeItem = new QTreeWidgetItem(); treeItem->setText(0, name); treeItem->setText(1, description); treeItemROOT ->addChild(treeItem); // add child to the root
-
@mrjj said in how to add children to the QTree Widget:
treeItem
thats what can u give any example code for that "Its a list of QTreeWidgetItems * ( pointers)
So you must add them to a QList then give QList to tree." -
@ManiRon
QList<QTreeWidgetItem> mylist;
mylist.append( new QTreeWidgetItem); // might want to set some text also
..
...
call addChildren with mylist.However, it wont help you build the tree, just other way of adding more than one item at a time.
-
My idea was to insert a list of data as a children to a toplevelitem
-
I gave like this QList<QTreeWidgetItem>m_Data;
m_Data.append(new QTreeWidgetItem);it throwed error saying
error: no matching function for call to 'QList<QTreeWidgetItem>::append(QTreeWidgetItem*)'
m_Data.append(new QTreeWidgetItem);
^ -
Hi
List must be of pointers.
QList<QTreeWidgetItem *>
(u missed the *) -
Now I gave like this sir,
QList<QTreeWidgetItem*>m_Data;
m_Data.append(new QTreeWidgetItem);QString Data = 0;
for(int i=1;i<3;i++)
{
Data = QString("SubItem"+QString::number(i));
m_Data.append(Data.toLatin1().constData());
item->addChildren(m_Data);
}it throws error
error: no matching function for call to 'QList<QTreeWidgetItem*>::append(const char*)'
m_Data.append(Data.toLatin1().constData());
^ -
hi
well u try to add strings to it.
m_Data.append(Data.toLatin1().constData());
and it wants a QTreeWidgetItem *I think you mean something like
for(int i=1;i<3;i++) { Data = QString("SubItem"+QString::number(i)); m_Data.append(Data.toLatin1().constData()); QTreeWidgetItem* item2=new QTreeWidgetItem(); // set text etc on item m_Data.append(item2); item->addChildren(m_Data); }
but why do it liek that since u new it there anyway so just add it directly ?
-
How are you trying to add it ?
aaa bbb ccc
or
aaa bbbb ccc ddd
-
This post is deleted! -
Something like this , top level item = aaaa
children = bbbb,
cccc,
dddd,
eeee,
and child of eeee is ffff