Unable to get the QString from a QTreeView (using : clicked(const QModelIndex &index)
Hello Everyone..
i've created a QStandardItemModel named userModel that goes to userTreeView and a slot: getSelectedUser(const QModelIndex &index),which listens to the default signal: clicked(const QModelIndex &index).This is the implementation of the getSelectedUser function:
----------------------------------------------------------------------------------
void MainWindow::getSelectedUser(const QModelIndex &index)
{
QStandardItem *user=userModel->itemFromIndex(index);
}
---------------------------------------------------------------------------------
..and the connection in the MainWindow:
---------------------------------------------------------------------------------
connect(userTreeView, SIGNAL(clicked(QModelIndex)),this, SLOT(getSelectedUser(QModelIndex)));
---------------------------------------------------------------------------------
the signal works fine and the index takes the column and row of the clicked point but the QStandardItem *user gives 0x0 in the debugger..
I would appreciate any help.
(p.s in the end the getSelectedUser function will have to retun a QString -now is void for debugging-..so if anyone knows how to get the QString right away instead of the QStandardItem, it would be great)
Thanks
Re: Unable to get the QString from a QTreeView (using : clicked(const QModelIndex &in
I am pretty sure that the signal is clicked(const QModelIndex&).
You can return a QString by getting the QStandardItem::text().
Edit: what does index.isValid() say?
Re: Unable to get the QString from a QTreeView (using : clicked(const QModelIndex &in
Hello
i've tried :
connect(userTreeView, SIGNAL(clicked(const QModelIndex&)),this, SLOT(getSelectedUser(const QModelIndex&)));
and
connect(userTreeView, SIGNAL(clicked(const QModelIndex&)),this, SLOT(getSelectedUser(QModelIndex)));
the QStandardItem *user sees 0x0 for both of these slots..i cant understand how the index return the row/column that clicked but user gets 0x0..
Re: Unable to get the QString from a QTreeView (using : clicked(const QModelIndex &in
The correct version is:
Code:
connect(userTreeView, SIGNAL(clicked(const QModelIndex&)),this, SLOT(getSelectedUser(const QModelIndex&)));
Do you have by any chance a QStandardItem class member named "user"?
Where do you see that user is NULL?
Re: Unable to get the QString from a QTreeView (using : clicked(const QModelIndex &in
ok i've changed the signal the way you told..
1)no i don't have a QStandardItem class member with the name "user"
2)i still see the 0x0 in the debugging for both adress and value of user
edit:index.isValid() returns true;
Re: Unable to get the QString from a QTreeView (using : clicked(const QModelIndex &in
Did you convert the index to the standard item by using the appropriate method of the model?
Re: Unable to get the QString from a QTreeView (using : clicked(const QModelIndex &in
Hello wysota
if you mean something like:
QString user =userModel->itemFromIndex(index)->data().toString();
i did but the programm crashes with QSting user Value=unable to evaluate value(debugger output).
if you mean something else please post the code because i'm really new to Qt.
Thanks