Converting QVariants/Retrieving data from views

4 views
Skip to first unread message

Ralf Van Bogaert

unread,
Apr 13, 2012, 5:31:48 AM4/13/12
to lqt-bi...@googlegroups.com
Hi,

I use a QListView that retrieves data from a QSqlTableModel.
The model contains paths to image files. The view displays thumbnails and truncated file names (without the path)
This is currently done like this;

local V=QVariant()
function Model:data(Index,Role)

if Role==0 then
local File=self:record(I:row()):value'File':toString()
V:setValue(QFileInfo(File):completeBaseName())
return V

elseif Role==1 then
local File=self:record(I:row()):value'File':toString()
V:setValue(QIcon(File))
return V

else return QSqlTableModel.data(self,I,R)end
end


As you can probably see, this operation isn't very efficient, since to retrieve the currently selected item's text, I need to
create a QSqlRecord for every row, and then get the wanted value from that.

What I was hoping to be able to do is;

local V=QVariant()
function Model:data(Index,Role)

if Role==0 then

local File=I:data(0):toString()
V:setValue(QFileInfo(File):completeBaseName())
return V

elseif Role==1 then

local File=I:data(0):toString()
V:setValue(QIcon(File))
return V

else return QSqlTableModel.data(self,I,R)end
end


In other words, get the text of the current item using QModelIndex:data() instead of the previous method.

However this crashes lqt with a stack overflow, I believe due to infinite recursion?

Is there a way to achieve this? Or maybe even another, better method I'm not seeing right now?

Regards

Ralf


Reply all
Reply to author
Forward
0 new messages