QAbstractTableModel emit dataChanged()

1220 views
Skip to first unread message

luafox

unread,
Dec 18, 2012, 4:01:08 AM12/18/12
to lqt-bi...@googlegroups.com
I am using QAbstractTableModel so that I can display the content of a lua table in a QTableView. Now I would like to change the values of the lua table when the user presses a GUI button. In principle this works, except that QTableView does not update automatically. If I select a column of the table after I made the changes then, and only then, QTableView shows the changes. So I need a way to tell QTableView to update it's display.

I think what I need to do is to emit the signal "dataChanged()" to the data model. I tried:

DataModel:dataChanged()

but I get the error: attempt to call method 'dataChanged' (a nil value), although "__methods()" shows: dataChanged(QModelIndex,QModelIndex) Protected Signal

I now think that I have to explicitly emit the signal, but searching through this lqt list seems to indicate that lqt does not support emitting signals. So is there any workaround for this problem?

Thank you very much!
Michael

Michal Kottman

unread,
Dec 19, 2012, 9:31:53 AM12/19/12
to lqt-bi...@googlegroups.com
This made me revisit lqt, along the way I kind-of solved the problem with multiple threads in Qt 4.8 in a fragile, but semi-working way (it works until you start overriding virtual methods which may end up being called in another thread, I can give more info if anyone is interested).

The problem with this problem - emitting signals - is that some are defined protected, like dataChanged is. A signal is just a method call. Being protected means that it cannot be called "from outside", like the binding code. This means that even if I force them to be public, the compiler ends up with this:

/usr/include/qt4/QtCore/qtimeline.h:129:10: error: ‘void QTimeLine::valueChanged(qreal)’ is protected
In file included from /opt/code/lua/lqt/b/qtcore_src/qtcore_merged_build.cpp:314:0:
/opt/code/lua/lqt/b/qtcore_src/qtcore_meta_QTimeLine.cpp:320:37: error: within this context

If anyone knows of any way how to call protected methods from outside of a class in C++, please let me know!

If nothing works, I will try doing this monstrosity prior to including Qt headers: #define protected public

luafox

unread,
Dec 21, 2012, 11:33:41 AM12/21/12
to lqt-bi...@googlegroups.com


Am Mittwoch, 19. Dezember 2012 15:31:53 UTC+1 schrieb Michal Kottman:
On 18 December 2012 10:01, luafox <in...@luafox.com> wrote:
I think what I need to do is to emit the signal "dataChanged()" to the data model.

This made me revisit lqt, along the way I kind-of solved the problem with multiple threads in Qt 4.8 in a fragile, but semi-working way (it works until you start overriding virtual methods which may end up being called in another thread, I can give more info if anyone is interested).

Yes, I am very interested in this solution even when it's not completely save
in all circumstances. Will this workaround also work with other signals or is
it specific to the dataChanged() call?

Thank you very much for looking on this problem!
Michael Gerbracht

Michal Kottman

unread,
Jan 5, 2013, 12:41:36 PM1/5/13
to lqt-bi...@googlegroups.com
Please try out the latest change in the repository (8e9ea6). This change makes it possible to call protected methods as public. This allows you to use protected methods in your own implementation of abstract classes, such as QAbstractItemModel. Since emiting signals is just calling a method, this change also makes it possible to emit protected signals.

An example of how this could work is in test/protected_test.lua - it creates a custom list model, which is backed up by a Lua table, and a method on how to update such table.

I guess this is the change I have been long waiting for. If no bugs are found within ~ two weeks, I will release this as lqt 1.0 and provide binaries to the LuaDist project.

luafox

unread,
Jan 19, 2013, 5:48:06 AM1/19/13
to lqt-bi...@googlegroups.com


Am Samstag, 5. Januar 2013 18:41:36 UTC+1 schrieb Michal Kottman:

Please try out the latest change in the repository (8e9ea6). This change makes it possible to call protected methods as public. This allows you to use protected methods in your own implementation of abstract classes, such as QAbstractItemModel. Since emiting signals is just calling a method, this change also makes it possible to emit protected signals.

An example of how this could work is in test/protected_test.lua - it creates a custom list model, which is backed up by a Lua table, and a method on how to update such table.

I guess this is the change I have been long waiting for. If no bugs are found within ~ two weeks, I will release this as lqt 1.0 and provide binaries to the LuaDist project.

 I would really like to try this but unfortunately I have never compiled any sources before (one reason for using lua...). But I think that it is not to complicated if you know what you have to do. What I did is download the lqt sources and I have also installed Qt 4.8.

Would someone be so nice to give me step-by-step instructions on how to compile lqt? I do not even know which compilter to use (gcc or Visual Studio?).

thanks,
Michael
Reply all
Reply to author
Forward
0 new messages