[Qt-interest] QListView's selectionModel is broken?

Kaleb Pederson kaleb.pederson at gmail.com
Tue Mar 17 19:07:43 CET 2009


2009/3/17 Ellen Kestrel <dragonflykes at gmail.com>:
> I have a QListView which has its data supplied by a QStringListModel, and I
> want to display information when each item in the QListView is clicked.  So,
> I tried
>
> connect (listView->selectionModel (), SIGNAL (currentChanged (const
> QModelIndex&, const QModelIndex&)), this, SLOT (display ()));
>
> When I run the program, the slot is never run.  There are no "No such
> signal/slot" messages - it looks like the currentChanged signal is simply
> never emitted.

The selectionModel might be replaced sometime after you do the
connect.  You might need to make sure that you have set your
stringlist model onto the listview before you try to do the connect
with the selection model.

Lastly, have you checked the return value on connect?  I presume it
worked since you didn't see any errors... but it never hurts to check
explicitely.

> I have done the exact same thing with a QTreeView, and it
> worked exactly the way I wanted it to.

Yeah, it should work.  I'm guessing it's just an ordering problem.

HTH,

--Kaleb


> I also tried connecting the
> currentRowChanged and selectionChanged signals, but those didn't work
> either.  Is there something special you have to do with a QListView, or is
> this a bug?  If it's a bug, is there a way to work around it?
>
> -- EK




More information about the Qt-interest-old mailing list