Solved how to add children to the QTree Widget
-
And i have another doubt ?
-
@ManiRon
yes message print out the variable name $$UNAME ( what it contains)
what is other doubt? -
@mrjj ok where i can see this message sir?
-
@ManiRon
in the Creator output pane.
below where code is.
-
@mrjj my anogther doubt is
I am trying to view the data in a list . i have specified already
-
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
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