how to add children to the QTree Widget
-
And i have another doubt .
I am trying to see the data which i have inserted into my QList . I can see the size but i cannot see the data.Code:
QList<QString> m_Data;
for(int i=1;i<3;i++)
{
Data = QString("SubItem"+QString::number(i));
m_Data.append(Data.toLatin1().constData());
QString H = m_Data.at(i); //trying to see data
qDebug()<<"Data"<< m_Data.at(i);
}while running the application crashesdonno why
-
@ManiRon
Hi
what you mean u can see the size but not the data?qDebug()<<"Data"<< m_Data.at(i); <<< u print index from 1,2,3
but u call append so first call, there is data in zero
but u print 1
then next loop
you print from 2, but only data in 0,1
and so on.
it starts in zero. so adjust the for loop.for(int i=0;i<2;i++) { Data = QString("SubItem"+QString::number(i+1)); m_Data.append(Data.toLatin1().constData()); qDebug()<<"Data"<< m_Data.at(i); //trying to see data }
-
@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
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
-
@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.