I have the following class defined (with alot of the extra stuff removed for clarity), and I have a question about its behavior:
{
Q_OBJECT;
public:
~DatabaseTreeWidget();
void Update_Tree_From_Flags();
signals:
void Message_Changed
(QString *Message
);
void DB_Flags_Changed(int Flags);
private slots:
bool Database_Is_Empty
(QString File_Name
);
void Click_Current_Database_Selection();
};
class DatabaseTreeWidget : public QTreeView
{
Q_OBJECT;
public:
DatabaseTreeWidget(QString Filename, QWidget *parent = 0);
~DatabaseTreeWidget();
void Update_Tree_From_Flags();
signals:
void Message_Changed(QString *Message);
void DB_File_Path_Changed(QString *File_Path, const QModelIndex *index);
void DB_Key_Changed(QString *Key);
void DB_Flags_Changed(int Flags);
private slots:
void Database_Item_Clicked(const QModelIndex &index);
bool Database_Is_Empty(QString File_Name);
void Click_Current_Database_Selection();
};
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:
void DatabaseTreeWidget::Click_Current_Database_Selection()
{
this->selectAll();
std::cout<<"Selected list size: "<<this->selectedIndexes().size()<<"\n";
//ScanDatabaseItem *Item = (ScanDatabaseItem *) selectedIndexes().at(0).internalPointer();
}
void DatabaseTreeWidget::Click_Current_Database_Selection()
{
this->selectAll();
std::cout<<"Selected list size: "<<this->selectedIndexes().size()<<"\n";
//ScanDatabaseItem *Item = (ScanDatabaseItem *) selectedIndexes().at(0).internalPointer();
}
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
Bookmarks