I have the following class defined (with alot of the extra stuff removed for clarity), and I have a question about its behavior:

Qt Code:
  1. class DatabaseTreeWidget : public QTreeView
  2. {
  3. Q_OBJECT;
  4. public:
  5. DatabaseTreeWidget(QString Filename, QWidget *parent = 0);
  6. ~DatabaseTreeWidget();
  7. void Update_Tree_From_Flags();
  8.  
  9. signals:
  10. void Message_Changed(QString *Message);
  11. void DB_File_Path_Changed(QString *File_Path, const QModelIndex *index);
  12. void DB_Key_Changed(QString *Key);
  13. void DB_Flags_Changed(int Flags);
  14.  
  15. private slots:
  16. void Database_Item_Clicked(const QModelIndex &index);
  17. bool Database_Is_Empty(QString File_Name);
  18. void Click_Current_Database_Selection();
  19. };
To copy to clipboard, switch view to plain text mode 

I can use this class with no problems except for one. I need to get the currently selected item and click it from the program (triggering another event). I tried some testing code as follows:

Qt Code:
  1. void DatabaseTreeWidget::Click_Current_Database_Selection()
  2. {
  3. this->selectAll();
  4. std::cout<<"Selected list size: "<<this->selectedIndexes().size()<<"\n";
  5. //ScanDatabaseItem *Item = (ScanDatabaseItem *) selectedIndexes().at(0).internalPointer();
  6. }
To copy to clipboard, switch view to plain text mode 

When I test the code, I would expect that I would get a count of all items in the tree. I get zero. I initally used currentIndex() but could not obtain the currently selected item in the widget.

How can I achieve this? Thanks.

JS