Failing to add topleveitem to QTreeWidget in QtCreator
-
I am facing an weird problem in QT programming using QT Creator.
Basically I have a class of following structure which is a Tree apparently.
class TestResult { public: TestResult(){} QString m_testID; QTreeWidgetItem* m_widgetItem; QList<TestResult*> m_Children; }During developing the object of the tree (using a different method) I have handled the
QTreeWidgetItemmembers also (i.e. Initialized it usingnew, addedQTreeWidgetItemmembers of the children (m_Children) of theTestResultobject to it etc.)Now when I trying to add the
QTreeWidgetItemmemeber of rootTestResultobject as a top level item of aQTreeWidget, it isn't getting added. I am doing this as following.TestResult *m_TestResultTree = new TestResult(); // This following method call perfectly develop the tree. It populate QTreeWidgetItem members also to make a corresponding tree-like straucture. developeTheTree(m_TestResultTree); // I have a form whose object is uiMainWin and it contains a QTreeWidget namely treeResults uiMainWin->treeResults->addTopLevelItem(m_TestResultTree->m_widgetItem);But, the
QTreeWidgetItemis not getting added to theQTreeWidget. The calltopLevelItemCountto theQTreeWidgetsimply returns 0.Can someone point out what I am doing wrong here ? Am I missing some property of
QTreeWidgethere ? Thanks in advance. -
I am facing an weird problem in QT programming using QT Creator.
Basically I have a class of following structure which is a Tree apparently.
class TestResult { public: TestResult(){} QString m_testID; QTreeWidgetItem* m_widgetItem; QList<TestResult*> m_Children; }During developing the object of the tree (using a different method) I have handled the
QTreeWidgetItemmembers also (i.e. Initialized it usingnew, addedQTreeWidgetItemmembers of the children (m_Children) of theTestResultobject to it etc.)Now when I trying to add the
QTreeWidgetItemmemeber of rootTestResultobject as a top level item of aQTreeWidget, it isn't getting added. I am doing this as following.TestResult *m_TestResultTree = new TestResult(); // This following method call perfectly develop the tree. It populate QTreeWidgetItem members also to make a corresponding tree-like straucture. developeTheTree(m_TestResultTree); // I have a form whose object is uiMainWin and it contains a QTreeWidget namely treeResults uiMainWin->treeResults->addTopLevelItem(m_TestResultTree->m_widgetItem);But, the
QTreeWidgetItemis not getting added to theQTreeWidget. The calltopLevelItemCountto theQTreeWidgetsimply returns 0.Can someone point out what I am doing wrong here ? Am I missing some property of
QTreeWidgethere ? Thanks in advance.@surajeet Have you called
setColumnCounton your tree widget yet? Nothing will show up in the tree if you haven't set your column count.Also the way you have made the
TestResultclass is the job of the tree itself. You don't need to track each widgetItem since the QTreeWidget already does that for you. You can even set custom user data, in your casem_testIDin the tree items.You have an entire layer of obfuscation you really don't need. It's harder to use and harder to support later on.
Also can you show us the code for uiMainWin? I have a feeling your tree isn't set up properly or you are using 2 different trees.