Results 1 to 3 of 3

Thread: Setting up the contents of treewidget in a slot of a subclass of treewidget not work!

  1. #1
    Join Date
    May 2010
    Posts
    4
    Platforms
    Windows Symbian S60

    Default Setting up the contents of treewidget in a slot of a subclass of treewidget not work!

    Dear All,
    Yet another novice question

    I have a subclass of QTreeWidget, called, QFileBrowser.
    Qt Code:
    1. class QFileBrowser : public QTreeWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. QFileBrowser(QWidget *parent);
    7. ~QFileBrowser();
    8. public slots:
    9. void onFilesFoldersSelected(QDir*, QStringList*);
    10. void onFileModeToggled(bool);
    11. private:
    12. QFileDialog::FileMode selMode;
    13. }
    To copy to clipboard, switch view to plain text mode 
    And in the main window, I have implemented a signal that is connected to the slot, onFilesFoldersSelected.
    Qt Code:
    1. QObject::connect(this, SIGNAL(filesFoldersSelected(QDir*, QStringList*)), ui->twFileBrowser, SLOT(onFilesFoldersSelected(QDir*, QStringList*)));
    To copy to clipboard, switch view to plain text mode 
    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 ..
    Qt Code:
    1. QList<QTreeWidgetItem *> itemList;
    2. QTreeWidgetItem treeItem((QTreeWidget *)this, *strList, 0);
    3. itemList.append(&treeItem);
    4. this->insertTopLevelItems(0, itemList); // I Expected this to do the job of inserting items in the tree
    5.  
    6. for (int i=0; i<strList->size(); i++)
    7. qDebug() << strList->at(i); // I can see that the strList has the strings that I am passing !!!
    To copy to clipboard, switch view to plain text mode 

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

    Thanks !!
    P.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Setting up the contents of treewidget in a slot of a subclass of treewidget not w

    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!

  3. #3
    Join Date
    May 2010
    Posts
    4
    Platforms
    Windows Symbian S60

    Default Re: Setting up the contents of treewidget in a slot of a subclass of treewidget not w

    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.

Similar Threads

  1. How to add subitem in treewidget
    By phillip_Qt in forum Qt Programming
    Replies: 11
    Last Post: 16th November 2009, 12:22
  2. Filtering a TreeWidget
    By soul_rebel in forum Qt Programming
    Replies: 6
    Last Post: 26th January 2008, 21:08
  3. How to set the sizehint for treeWidget
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2007, 12:35
  4. By default TreeWidget width setting in DockWidget
    By santosh.kumar in forum Qt Programming
    Replies: 0
    Last Post: 31st May 2007, 06:55
  5. Painting TreeWidget
    By VireX in forum Qt Programming
    Replies: 9
    Last Post: 9th May 2007, 09:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.