PDA

View Full Version : Setting up the contents of treewidget in a slot of a subclass of treewidget not work!



prakash437
18th May 2010, 21:21
Dear All,
Yet another novice question :)

I have a subclass of QTreeWidget, called, QFileBrowser.


class QFileBrowser : public QTreeWidget
{
Q_OBJECT

public:
QFileBrowser(QWidget *parent);
~QFileBrowser();
public slots:
void onFilesFoldersSelected(QDir*, QStringList*);
void onFileModeToggled(bool);
private:
QFileDialog::FileMode selMode;
}

And in the main window, I have implemented a signal that is connected to the slot, onFilesFoldersSelected.


QObject::connect(this, SIGNAL(filesFoldersSelected(QDir*, QStringList*)), ui->twFileBrowser, SLOT(onFilesFoldersSelected(QDir*, QStringList*)));

Everything works fine and whenever, i am emitting a signal, I land in the slot. I also see that the pointers point to the data passed in the main window. However, when I try to set the tree as in below, I could see nothing ..


QList<QTreeWidgetItem *> itemList;
QTreeWidgetItem treeItem((QTreeWidget *)this, *strList, 0);
itemList.append(&treeItem);
this->insertTopLevelItems(0, itemList); // I Expected this to do the job of inserting items in the tree

for (int i=0; i<strList->size(); i++)
qDebug() << strList->at(i); // I can see that the strList has the strings that I am passing !!!


I am sure, im overlooking something small. Could anyone point me to that please !!!

Thanks !!
P.

Lykurg
18th May 2010, 22:04
You have to create treeItem on the heap otherwise it will be destroyed after your slot finished. This is the reason you can't see anything!

prakash437
18th May 2010, 22:44
Hi ..
Thank you for your reply .. It works now ..

I was expecting that some object was being destroyed but was only looking at the treewidget object. Trying to make sure it was not not destroyed but never realized that the item objects are qually important !!

Thanks again !!
P.