how to add children to the QTree Widget
-
I am trying to add children to the QTree widget . but i am facing some problems.
My code:
// Create new item (top level item)
QTreeWidgetItem *topLevelItem = new QTreeWidgetItem(ui->treeWidget);// Set text for item topLevelItem->setText(0,"Item"); // Add it on our tree as the top item. ui->treeWidget->addTopLevelItem(topLevelItem); // Create new item and add as child item
QTreeWidgetItem *item=new QTreeWidgetItem(topLevelItem);
// Set text for item
//item->setText(0,"SubItem");QList<QString>m_Data; for(int i=1;i<3;i++) { QString Data = QString("SubItem"+QString::number(i)); m_Data.append(Data); } item->addChildren(m_Data);
-
Hi
You are not really telling what kind of problems :)
but this tutorial explain usage pretty well in my opinionhttps://www.bogotobogo.com/Qt/Qt5_QTreeWidget.php
The main idea is either to add as a top level item or
add to other parent to build a tree like structure.void Dialog::addTreeRoot(QString name, QString description) { // QTreeWidgetItem(QTreeWidget * parent, int type = Type) QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget); // QTreeWidgetItem::setText(int column, const QString & text) treeItem->setText(0, name); treeItem->setText(1, description); addTreeChild(treeItem, name + "A", "Child_first"); addTreeChild(treeItem, name + "B", "Child_second"); } void Dialog::addTreeChild(QTreeWidgetItem *parent, QString name, QString description) { // QTreeWidgetItem(QTreeWidget * parent, int type = Type) QTreeWidgetItem *treeItem = new QTreeWidgetItem(); // QTreeWidgetItem::setText(int column, const QString & text) treeItem->setText(0, name); treeItem->setText(1, description); // QTreeWidgetItem::addChild(QTreeWidgetItem * child) parent->addChild(treeItem); }
-
@mrjj
Actually i want to add n number of children and child to that n number of children thats my question. But using the code.Example:
I want to store the data in a Qlist and insert it in Qtree widget as children using the "addchildren"member function -
@ManiRon
Ok, but there nothing magic to it.
If you add it like
QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget);its a top level item
if you use that item as parent, likeQTreeWidgetItem *treeItem2 = new QTreeWidgetItem();
treeItem ->addChild(treeItem2 );it becomes a child of that parent. and so on.
so you simply use the last item as parent for next if u want it to go
aaa bbbb cccc
-
@mrjj ok but if i want to add n number of children under top level item how should i do that.
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);
} -
Sir i am trying to add
uinx{
LIBS+= -L$$PWD/.../lib/linus/-lData
LIBS+= -L$$PWD/.../lib/Xenomai/-lData1 -lrtdm -lrt -lxenomai
}
win32
{
LIBS += path
}I am adding the linux and xenomai library and trying to compile . but it throws error. As it detects the linux library and it couldnt find the xenomai library it throws error.
My question is i want to define all my library and based on the platform or OS i am running it should detect its particular library.
For example : linux, xenomai, windiows. These are the platforms i am running the application. Why i ask this is because every time i have to add the corresponding library and compile it and the run the application . So is there any solution for this? -
One of the person from this forum told me to use "unix" and "win32". But i asked for linux,xenomai what should i define, he told to use "unix" itself. But i have separate library for linux and xenomai. but i want to add both is there any way?
-
Hi it seems ok what you did
except you missspelled unix (uinx)
and it sometimes a bit funny with scopes so make sure t to
unix {
}
and not
unix
{
}
http://doc.qt.io/qt-5/qmake-advanced-usage.html
http://doc.qt.io/qt-5/third-party-libraries.html -
Ok Sir,
But my doubt is i am able to add the library.
But i am adding another library that supports xenomai. while running the application in linux OS it goes to the unix{
LIBS+= -L$$PWD/.../lib/linus/-lData
LIBS+= -L$$PWD/.../lib/Xenomai/-lData1 -lrtdm -lrt -lxenomai
}
part and searches for the library which is my problem, I want the application to detect the library based on the platform i run. As one person from Qt forum said unix is common for xenomai, linux. So is there any possibility i can make my application to run that particular library based on OS platform? -
its linux sir,
but for xenomai also it is unix i think so
unix{
LIBS+= -L$$PWD/.../lib/linus/-lData
LIBS+= -L$$PWD/.../lib/Xenomai/-lData1 -lrtdm -lrt -lxenomai
}this is my problem sir,
I am want to run library if its linux i want linux library and if its xenomai i want xenomai library to run
-
Hi
Now i understand.
For qmake both plain linux and xenomai will be the same
as far as i know. (unix)you can call .sh script and things like that from the pro file
so maybe you can detect your self if linux or xenomai ?
http://doc.qt.io/archives/qt-4.8/qmake-function-reference.html#system-commandCheck what
UNAME = $$system(uname -s) contains( UNAME, [lL]inux ):message( This looks like Linux ($$UNAME) to me )
will output
also did u try what been suggested in
https://forum.qt.io/topic/94393/how-to-add-macro-for-the-libs-in-the-pro-file/9 -
@mrjj said in how to add children to the QTree Widget:
UNAME = $$system(uname -s)
contains( UNAME, [lL]inux ):message( This looks like Linux ($$UNAME) to me )So thsi is for linux?
UNAME = $$system(uname -s)
contains( UNAME, [lL]inux ):message( This looks like Linux ($$UNAME) to me )If i want to check for xenomai what should i do sir?
-
@ManiRon
Hi
Yes you can do it.
But you need to find out how. I dont have xenomai
installed so i cant say how we can spot the difference between plain linux and
xenomai
so try
UNAME = $$system(uname -s)
on both systems and see what it types.
If different, you can use that as a flag