[kind of solved] subclassed QAbstractTableModel::setData does not get called
-
It seems, as if QAbstractTableModel subclasses do not like nlohmann::json parameters to be passed to their constructor. I've started another project with basically the same subclass and it shows the same error of an undefined reference to vtable. I guess the setData method would not get called, even if i found a way to get it to compile.
Could this be an issue of the nlohmann::json library? Or what could one do to further investigate the issue?
-
It seems, as if QAbstractTableModel subclasses do not like nlohmann::json parameters to be passed to their constructor. I've started another project with basically the same subclass and it shows the same error of an undefined reference to vtable. I guess the setData method would not get called, even if i found a way to get it to compile.
Could this be an issue of the nlohmann::json library? Or what could one do to further investigate the issue?
@andi456 said in subclassed QAbstractTableModel::setData does not get called:
as if QAbstractTableModel subclasses do not like nlohmann::json parameters to be passed to their constructor.
Don't know what you mean.
QAbstractTableModeldoesn't know anything about JSON. What you do withnlohmann::jsonparameters is up to you. -
Well, that's why I tried to pass a nlohmann::json argument to the constructor, which results in the obscure "undefined reference to vtable" error for the QAbstractTableModel subclass. After some research on the internet this error can have all kinds of causes. But I do not see any obvious error in my code.
-
What build system do you use? Is the moc file for zaubertablemodel.h generated, compiled and linked?
-
Hi,
Might be a silly question but do you build the class code along with your test ?
-
@SGaist No, I've written both a minimal test project and a test. The errors were similar. After running qmake on the minimal testproject, new errors occurred:
:-1: Fehler: moc_ztablemodel.o:(.data.rel.ro._ZTV11ZTableModel[_ZTV11ZTableModel]+0xb0): undefined reference to `ZTableModel::headerData(int, Qt::Orientation, int) const'And so on for all the reimplemented methods of QAbstractTableModel.
The moc_* files are there obviously but cannot be linked somehow?
-
Missing symbols suggests that you might be:
- not building the class sources
- not implementing the methods
One thing you can is start from an empty class and the gradually add the methods to see where it breaks
-
Don't i have to implement at least
code_text QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;``` code_text? That's what I did in my minimal test class .
-
@andi456 said in subclassed QAbstractTableModel::setData does not get called:
That's what I did in my minimal test class .
But you declared headerData() without providing an implementation.
-
@andi456 said in subclassed QAbstractTableModel::setData does not get called:
That's what I did in my minimal test class .
But you declared headerData() without providing an implementation.
@Christian-Ehrlicher The relevant parts of the implementation can be found in my first post in the second code block. I just copied the necessary parts to my minimal test example, created with qtcreator.
-
@Christian-Ehrlicher The relevant parts of the implementation can be found in my first post in the second code block. I just copied the necessary parts to my minimal test example, created with qtcreator.
@andi456 but even there I see no headerData() implementation...
-
Here it is:
QVariant ZTableModel::headerData(int section, Qt::Orientation orientation, int role) const { QList<QString> headerliste = ZTableModel::get_header(j_zl); if (role != Qt::DisplayRole) { return QVariant(); } if (orientation == Qt::Horizontal) { for (int i=0; i < headerliste.size(); ++i) { QString s = headerliste.at(i); if (i == section) { return s; break; } } } -
@Christian-Ehrlicher The relevant parts of the implementation can be found in my first post in the second code block. I just copied the necessary parts to my minimal test example, created with qtcreator.
-
Here it is:
QVariant ZTableModel::headerData(int section, Qt::Orientation orientation, int role) const { QList<QString> headerliste = ZTableModel::get_header(j_zl); if (role != Qt::DisplayRole) { return QVariant(); } if (orientation == Qt::Horizontal) { for (int i=0; i < headerliste.size(); ++i) { QString s = headerliste.at(i); if (i == section) { return s; break; } } }@andi456 said in subclassed QAbstractTableModel::setData does not get called:
Here it is:
Your post crossed with mine.
Could you please delete all object files etc. and do a clean rebuild from scratch. If you still get an error could you copy & paste that/those.
-
After implementing the setData and flags and making use of the convenient debugging capabilities of qtcreator, I can now tell that setData is being called, when i enter something from the keyboard, which seems to be discarded afterwards.
Edit: Wrong impression on first Debug run.
Update: The new value is being put into the json-object, according to the debugging information, dataChanged is being emitted too, but for some reason the change is not being displayed. What might i be missing?
I missed writing back the data into the json list in the setData method.
-
First of all, thank you all for your support. The reason, why I wrote "kind of solved" into the headline of the post, is the following. I just loaded the original project into qtcreator in order to debug it. qtcreator seems to have run some scripts and the setData method got actually called without the code having changed at all. Unfortunately, I do not know what was necessary. (I just used vim for writing the program before.)