4 A
= QApplication(1, {'Protected test'})
6 -- We will implement our custom model
7 M
= QAbstractListModel()
9 -- stored in the environment table of the userdata
10 M
.luaData
= {'Hello', 'World'}
12 -- these are implemented virtual methods
17 local empty
= QVariant()
18 function M
:data(index
, role
)
19 if role
== Qt
.ItemDataRole
.DisplayRole
then
20 local row
= index
:row()
21 return QVariant(self
.luaData
[row
+ 1])
26 -- this is a custom helper function
27 function M
:addAnotherString(str
)
28 table.insert(self
.luaData
, str
)
29 local row
= #self
.luaData
- 1
30 local index
= self
:createIndex(row
, 0, 0)
31 self
:dataChanged(index
, index
)
34 -- some simple layout - list and a button
40 B
= QPushButton('Add Lua data')
42 B
:connect('2clicked()', function()
43 M
:addAnotherString('Added text ' .. counter
)