[SOLVED] how to get the QmodelIndex to a QString?
-
i am trying to get the current index of the listwidget but i am having problems. when i type
@
if (ui->userListWidget->currentIndex() == 0)@i get an error: no match for 'operator==' in 'QAbstractItemView::currentIndex() const() == 0'. candidates are: bool QModelIndex::operator==(const QModelIndex&) const
when i type
@
QString temp = ui->userListWidget->currentIndex(); @to get the string, i get the error: conversion from 'QModelIndex' to non-scalar type 'QString' requested.
how to get the QmodelIndex to a QString?
[edit, please add @ code tags to make your post easier to read, Eddy]
-
"The docs":http://developer.qt.nokia.com/doc/qt-4.8/qabstractitemview.html#currentIndex say that currentIndex returns a QModelIndex
So you could use it's "isValid member":http://developer.qt.nokia.com/doc/qt-4.8/qmodelindex.html#isValid
-
I don't quiet understand what you want to achieve generally speaking. But if it is your goal to show the row number of the selected item you could use "currentRow":http://developer.qt.nokia.com/doc/qt-4.8/qlistwidget.html#currentRow-prop.
This gives you an int, which you can use in your textEdit.
Is that what you want? -
What is "the string"? What do you want to append to your text edit? If you have a snippet of code that does not work, then please tell your fellow forumistas what you want to achieve. It's hard to guess this from broken code. I do have a guess and I'm pretty sure I now what you want to do, but I want to hear that from you.
-
lets say there are three items in the listwidget. when a user clicks the second item, i want to get the index from it. so the code would return number 2. the listwidget.currentindex does return it but in a modelindex. i need the number to be in a string so that i can work with it.
after reading Eddy's last post, i tested the currentRow and it is just what i was looking for. i marked this topic as solved.