[kind of solved] subclassed QAbstractTableModel::setData does not get called
-
Hi,
trying to build a bunch of TableViews displayed in Tabs of a TabWidget from the data provided by a .json file with a library external to qt called nlohmann/json.hpp (I haven't noticed the existence of the QJson library until yesterday), I had to subclass QAbstractTableModel which successfully displays the data. The next step would be to make some columns editable, which does seem to work as well. But trying to enter data in a editable column does not result in a call for the reimplemented setData method. But I cannot figure out why.
For my little project I mimicked the QtCreator approach with a ui_mainwindow.h file written by hand, because I wanted to be able to use lists of widget (pointers):
#ifndef UI_MAINWINDOW_H #define UI_MAINWINDOW_H #include <iostream> #include <fstream> #include <QtCore/QVariant> #include <QtWidgets/QApplication> #include <QtWidgets/QFrame> #include <QtWidgets/QLabel> #include <QtWidgets/QMainWindow> #include <QtWidgets/QWidget> #include <QtWidgets/QTabWidget> #include <QtWidgets/QHBoxLayout> #include <QList> #include <QTableView> #include <QtWidgets/QHeaderView> #include <nlohmann/json.hpp> #include "zauberdata.h" #include "zaubertablemodel.h" #include "zaubertablemodel.cpp" QT_BEGIN_NAMESPACE class Ui_MainWindow { public: QWidget *centralwidget; QWidget *tabwidget; QWidget *tabwidget2; QLabel *TestLabel; QList<QHBoxLayout *> tabs_hLayout; // ZauberTableModel *model; //QTableView *tabletester; QTabWidget *Tabulator; ZauberData *Zauberei; nlohmann::json j_zauberei; QList<QWidget *> get_tablist (int tabnum) { QList<QWidget*> tablist; for (int i=0; i < tabnum; ++i) { tablist.append(new QWidget()); } return tablist; } QList<QTableView *> tableviews; QList<ZauberTableModel *> models; nlohmann::json load_zauber_json_from_file(std::string filename) { std::ifstream imagicstream(filename); nlohmann::json j_zauberliste; if (!imagicstream.is_open()) { std::cout << "Zauber laden schlug fehl!"; } else { std::cout << "should work" << std::endl; imagicstream >> j_zauberliste ; int len = j_zauberliste.size(); std::cout << "Datei erfolgreich geladen " << std::to_string(len) << "Eintraege geladen von " << filename << std::endl; } return j_zauberliste; } void setupUi(QMainWindow *MainWindow) { j_zauberei = load_zauber_json_from_file("/home/andi/Projekte/qt/pathfinder-json/waldläuferzauber-erw.json"); Zauberei = new ZauberData(j_zauberei); QList<int> zeilenliste = Zauberei->get_zeilen_from_json(); MainWindow->resize(800, 600); centralwidget = new QWidget(MainWindow); Tabulator = new QTabWidget(centralwidget); Tabulator->setGeometry(QRect(4, 4, 700, 400)); TestLabel = new QLabel(tabwidget); QList<QWidget *> tabs = get_tablist(zeilenliste.size()); QList<QTableView *> tableviews; QList<ZauberTableModel *> models; QList<QHBoxLayout *> tabs_hLayout; for (int i=0; i<zeilenliste.size(); ++i) { tabs.at(i)->setObjectName(QString("TabGrad%1").arg(i)); QString s = "Grad " + QString::number(i); Tabulator->addTab(tabs.at(i), s); tableviews.append(new QTableView(tabs.at(i))); int zeilen = zeilenliste.at(i); std::cout << "Zeilenzahl: " << zeilen << std::endl; models.append(new ZauberTableModel(i, j_zauberei, centralwidget)); tabs_hLayout.append(new QHBoxLayout(tabs.at(i))); } for (int i=0; i<zeilenliste.size(); ++i) { tableviews.at(i)->setModel(models.at(i)); tableviews.at(i)->horizontalHeader()->setSectionsMovable(true); tabs_hLayout.at(i)->addWidget(tableviews.at(i)); } MainWindow->setCentralWidget(centralwidget); } };#include "zaubertablemodel.h" #include "zauberdata.h" #include <nlohmann/json.hpp> #include <string> QVariant ZauberTableModel::data(const QModelIndex &index, int role) const { std::cout << "data Methode" << std::endl; if (role == Qt::DisplayRole) { int zeile, spalte; int iteration = -1; zeile = index.row(); //std::cout << " zeilen " << zeile << std::endl; zeile = ZauberTableModel::zeilenjustierung(zeile); //std::cout << "OK zeilen " << zeile << std::endl; spalte = index.column(); nlohmann::json row_obj = Zauberei->get_row_obj(zeile); for (auto& el :row_obj.items()) { ++iteration; std::string tn = el.value().type_name(); //std::cout << "Urtyp " << el.value().type() << std::endl; int bool_comp = tn.compare("boolean"); int number_comp = tn.compare("number"); if ((el.value().type()==nlohmann::json::value_t::string) && (iteration==spalte)) { //std::cout << "Type " << el.value().type_name() << " Key " << el.key() << std::endl; std::cout << "Schlüssel "<< el.key() << " Spalte " << iteration << "Zeile "<< zeile << std::endl; QString s = QString::fromStdString(el.value()); return s; break; } else if ((bool_comp == 0) && (iteration==spalte)) { std::cout << "Schlüssel "<< el.key() << " Spalte " << iteration << "Zeile "<< zeile << std::endl; bool flag = el.value(); // std::cout << "Flags auch?" << std::endl; //QString s = QString::number(flag); return flag; break; } else if ((el.value().type()==nlohmann::json::value_t::number_integer) && (iteration==spalte)) { int counter = el.value(); std::cout << "Zahlen auch? " << counter << std::endl; //QString s = QString::number(counter); return counter; break; } else if ((number_comp == 0) && (iteration == spalte)) { // std::cout << "Wie jetzt?" << std::endl; std::cout << "Schlüssel "<< el.key() << " Spalte " << iteration << "Zeile "<< zeile << std::endl; int counter = el.value(); //QString s = QString::number(counter); return counter; break; } } } return QVariant(); } bool ZauberTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { std::cout << "Dies ist die setData Methode" << std::endl; if (role == Qt::EditRole) { int zeile, spalte; zeile = ZauberTableModel::zeilenjustierung(index.row()); spalte = index.column(); nlohmann::json row_obj = Zauberei->get_row_obj(zeile); QList<QString> headerliste = Zauberei->get_header(); for (int i=0; i<headerliste.size(); ++i) { if (i == spalte) { QString qs = headerliste.at(i); std::string spaltenname = qs.toStdString(); QString s; QVariant qvtest = value; if ((value.canConvert<QString>()) && (qvtest.convert(QVariant::String))) { s = value.toString(); std::string neuerstringwert = s.toStdString(); row_obj[spaltenname] = neuerstringwert; } else if ((value.canConvert<int>()) && (qvtest.convert(QVariant::Int))) { int neuerzahlwert = value.toInt(); row_obj[spaltenname] = neuerzahlwert; } else if ((value.canConvert<bool>()) && (qvtest.convert(QVariant::Bool))) { std::cout << "Überhaupt angekommen?" << std::endl; bool neuerboolwert = value.toBool(); row_obj[spaltenname] = neuerboolwert; } } } emit dataChanged(index, index, {role}); return true; } else { return false; } } Qt::ItemFlags ZauberTableModel::flags(const QModelIndex &index) const { int editspalte = ZauberTableModel::get_spalte_from_header("Beschreibung"); int spalte = index.column(); Qt::ItemFlags f;// = ZauberTableModel::flags(index);; std::cout << "Editierbar " << editspalte << std::endl; if (spalte == editspalte) { f = Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled; } else { f = Qt::ItemIsEnabled; } return f; }The above shows the code of the subclassed QAbstractTableModel. So how could I debug this? Could it be that setData does not get called because I use a QList of models? Or should I learn to use the QJson class. (Btw. I know the code is still ugly, but I first wanted to get the basics to work before cleaning up.)
Kind regards,
Andreas
-
Hi,
trying to build a bunch of TableViews displayed in Tabs of a TabWidget from the data provided by a .json file with a library external to qt called nlohmann/json.hpp (I haven't noticed the existence of the QJson library until yesterday), I had to subclass QAbstractTableModel which successfully displays the data. The next step would be to make some columns editable, which does seem to work as well. But trying to enter data in a editable column does not result in a call for the reimplemented setData method. But I cannot figure out why.
For my little project I mimicked the QtCreator approach with a ui_mainwindow.h file written by hand, because I wanted to be able to use lists of widget (pointers):
#ifndef UI_MAINWINDOW_H #define UI_MAINWINDOW_H #include <iostream> #include <fstream> #include <QtCore/QVariant> #include <QtWidgets/QApplication> #include <QtWidgets/QFrame> #include <QtWidgets/QLabel> #include <QtWidgets/QMainWindow> #include <QtWidgets/QWidget> #include <QtWidgets/QTabWidget> #include <QtWidgets/QHBoxLayout> #include <QList> #include <QTableView> #include <QtWidgets/QHeaderView> #include <nlohmann/json.hpp> #include "zauberdata.h" #include "zaubertablemodel.h" #include "zaubertablemodel.cpp" QT_BEGIN_NAMESPACE class Ui_MainWindow { public: QWidget *centralwidget; QWidget *tabwidget; QWidget *tabwidget2; QLabel *TestLabel; QList<QHBoxLayout *> tabs_hLayout; // ZauberTableModel *model; //QTableView *tabletester; QTabWidget *Tabulator; ZauberData *Zauberei; nlohmann::json j_zauberei; QList<QWidget *> get_tablist (int tabnum) { QList<QWidget*> tablist; for (int i=0; i < tabnum; ++i) { tablist.append(new QWidget()); } return tablist; } QList<QTableView *> tableviews; QList<ZauberTableModel *> models; nlohmann::json load_zauber_json_from_file(std::string filename) { std::ifstream imagicstream(filename); nlohmann::json j_zauberliste; if (!imagicstream.is_open()) { std::cout << "Zauber laden schlug fehl!"; } else { std::cout << "should work" << std::endl; imagicstream >> j_zauberliste ; int len = j_zauberliste.size(); std::cout << "Datei erfolgreich geladen " << std::to_string(len) << "Eintraege geladen von " << filename << std::endl; } return j_zauberliste; } void setupUi(QMainWindow *MainWindow) { j_zauberei = load_zauber_json_from_file("/home/andi/Projekte/qt/pathfinder-json/waldläuferzauber-erw.json"); Zauberei = new ZauberData(j_zauberei); QList<int> zeilenliste = Zauberei->get_zeilen_from_json(); MainWindow->resize(800, 600); centralwidget = new QWidget(MainWindow); Tabulator = new QTabWidget(centralwidget); Tabulator->setGeometry(QRect(4, 4, 700, 400)); TestLabel = new QLabel(tabwidget); QList<QWidget *> tabs = get_tablist(zeilenliste.size()); QList<QTableView *> tableviews; QList<ZauberTableModel *> models; QList<QHBoxLayout *> tabs_hLayout; for (int i=0; i<zeilenliste.size(); ++i) { tabs.at(i)->setObjectName(QString("TabGrad%1").arg(i)); QString s = "Grad " + QString::number(i); Tabulator->addTab(tabs.at(i), s); tableviews.append(new QTableView(tabs.at(i))); int zeilen = zeilenliste.at(i); std::cout << "Zeilenzahl: " << zeilen << std::endl; models.append(new ZauberTableModel(i, j_zauberei, centralwidget)); tabs_hLayout.append(new QHBoxLayout(tabs.at(i))); } for (int i=0; i<zeilenliste.size(); ++i) { tableviews.at(i)->setModel(models.at(i)); tableviews.at(i)->horizontalHeader()->setSectionsMovable(true); tabs_hLayout.at(i)->addWidget(tableviews.at(i)); } MainWindow->setCentralWidget(centralwidget); } };#include "zaubertablemodel.h" #include "zauberdata.h" #include <nlohmann/json.hpp> #include <string> QVariant ZauberTableModel::data(const QModelIndex &index, int role) const { std::cout << "data Methode" << std::endl; if (role == Qt::DisplayRole) { int zeile, spalte; int iteration = -1; zeile = index.row(); //std::cout << " zeilen " << zeile << std::endl; zeile = ZauberTableModel::zeilenjustierung(zeile); //std::cout << "OK zeilen " << zeile << std::endl; spalte = index.column(); nlohmann::json row_obj = Zauberei->get_row_obj(zeile); for (auto& el :row_obj.items()) { ++iteration; std::string tn = el.value().type_name(); //std::cout << "Urtyp " << el.value().type() << std::endl; int bool_comp = tn.compare("boolean"); int number_comp = tn.compare("number"); if ((el.value().type()==nlohmann::json::value_t::string) && (iteration==spalte)) { //std::cout << "Type " << el.value().type_name() << " Key " << el.key() << std::endl; std::cout << "Schlüssel "<< el.key() << " Spalte " << iteration << "Zeile "<< zeile << std::endl; QString s = QString::fromStdString(el.value()); return s; break; } else if ((bool_comp == 0) && (iteration==spalte)) { std::cout << "Schlüssel "<< el.key() << " Spalte " << iteration << "Zeile "<< zeile << std::endl; bool flag = el.value(); // std::cout << "Flags auch?" << std::endl; //QString s = QString::number(flag); return flag; break; } else if ((el.value().type()==nlohmann::json::value_t::number_integer) && (iteration==spalte)) { int counter = el.value(); std::cout << "Zahlen auch? " << counter << std::endl; //QString s = QString::number(counter); return counter; break; } else if ((number_comp == 0) && (iteration == spalte)) { // std::cout << "Wie jetzt?" << std::endl; std::cout << "Schlüssel "<< el.key() << " Spalte " << iteration << "Zeile "<< zeile << std::endl; int counter = el.value(); //QString s = QString::number(counter); return counter; break; } } } return QVariant(); } bool ZauberTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { std::cout << "Dies ist die setData Methode" << std::endl; if (role == Qt::EditRole) { int zeile, spalte; zeile = ZauberTableModel::zeilenjustierung(index.row()); spalte = index.column(); nlohmann::json row_obj = Zauberei->get_row_obj(zeile); QList<QString> headerliste = Zauberei->get_header(); for (int i=0; i<headerliste.size(); ++i) { if (i == spalte) { QString qs = headerliste.at(i); std::string spaltenname = qs.toStdString(); QString s; QVariant qvtest = value; if ((value.canConvert<QString>()) && (qvtest.convert(QVariant::String))) { s = value.toString(); std::string neuerstringwert = s.toStdString(); row_obj[spaltenname] = neuerstringwert; } else if ((value.canConvert<int>()) && (qvtest.convert(QVariant::Int))) { int neuerzahlwert = value.toInt(); row_obj[spaltenname] = neuerzahlwert; } else if ((value.canConvert<bool>()) && (qvtest.convert(QVariant::Bool))) { std::cout << "Überhaupt angekommen?" << std::endl; bool neuerboolwert = value.toBool(); row_obj[spaltenname] = neuerboolwert; } } } emit dataChanged(index, index, {role}); return true; } else { return false; } } Qt::ItemFlags ZauberTableModel::flags(const QModelIndex &index) const { int editspalte = ZauberTableModel::get_spalte_from_header("Beschreibung"); int spalte = index.column(); Qt::ItemFlags f;// = ZauberTableModel::flags(index);; std::cout << "Editierbar " << editspalte << std::endl; if (spalte == editspalte) { f = Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled; } else { f = Qt::ItemIsEnabled; } return f; }The above shows the code of the subclassed QAbstractTableModel. So how could I debug this? Could it be that setData does not get called because I use a QList of models? Or should I learn to use the QJson class. (Btw. I know the code is still ugly, but I first wanted to get the basics to work before cleaning up.)
Kind regards,
Andreas
-
Please put your code block inside the Code tags offered by the forum posts. You can see how difficult what you have posted is to read, it has been broken into multiple segments, and the indentation is all over the place.
-
Please make an attempt to edit your code down to a minimal example of whatever your issue is. Most of yours seems irrelevant to the actual problem. Nobody wants to wade through hundreds of lines to find a problem.
-
Show your declarations of
setData()&data()from your class.hfile. Have you used C++overridekeyword to make sure your signatures are correct, e.g. I am thinking of the defaultedroleparameter.
-
-
Hi
did you overwrite the flags function to say its editable?
https://doc.qt.io/qt-5/qabstractitemmodel.html#flags
ItemIsEnabled and ItemIsSelectable is default so maybe thats the issue.
Seems Qt::ItemIsEditable is not default on as far as i know. -
Hi
did you overwrite the flags function to say its editable?
https://doc.qt.io/qt-5/qabstractitemmodel.html#flags
ItemIsEnabled and ItemIsSelectable is default so maybe thats the issue.
Seems Qt::ItemIsEditable is not default on as far as i know.The next step would be to make some columns editable, which does seem to work as well.
But trying to enter data in a editable column does not result in a call for the reimplemented setData method.I assume that means the cell is editable, else the OP would surely have said so....
-
The next step would be to make some columns editable, which does seem to work as well.
But trying to enter data in a editable column does not result in a call for the reimplemented setData method.I assume that means the cell is editable, else the OP would surely have said so....
Yes the cell is editable, but after entering some data from the keyboard and pressing enter, the original data shows up again, without setData being called, from what I can tell.
Btw., sorry for the somehow convoluted output, but I'll try to correct it in a minute.
The declarations of the model look like this:```
#ifndef ZAUBERTABLEMODEL_H
#define ZAUBERTABLEMODEL_H#include <QAbstractTableModel>
#include <nlohmann/json.hpp>
#include <zauberdata.h>class ZauberTableModel : public QAbstractTableModel {
Q_OBJECT public: ZauberTableModel(int tabnummer, nlohmann::json j_zauberliste, QObject *parent); int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; int get_tabnum() const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE; //override; Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;//override; private: int get_spalte_from_header(QString headername) const; int zeilenjustierung(int zidx) const; ZauberData *Zauberei; nlohmann::json j_zauber; int tnum;};
#endif -
Yes the cell is editable, but after entering some data from the keyboard and pressing enter, the original data shows up again, without setData being called, from what I can tell.
Btw., sorry for the somehow convoluted output, but I'll try to correct it in a minute.
The declarations of the model look like this:```
#ifndef ZAUBERTABLEMODEL_H
#define ZAUBERTABLEMODEL_H#include <QAbstractTableModel>
#include <nlohmann/json.hpp>
#include <zauberdata.h>class ZauberTableModel : public QAbstractTableModel {
Q_OBJECT public: ZauberTableModel(int tabnummer, nlohmann::json j_zauberliste, QObject *parent); int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; int get_tabnum() const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE; //override; Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;//override; private: int get_spalte_from_header(QString headername) const; int zeilenjustierung(int zidx) const; ZauberData *Zauberei; nlohmann::json j_zauber; int tnum;};
#endif@andi456
Can you show the flag function ?
(just to be sure)Nothing pops up reading the code.
you could try run it through
https://doc.qt.io/qt-5/qabstractitemmodeltester.html -
@andi456
Can you show the flag function ?
(just to be sure)Nothing pops up reading the code.
you could try run it through
https://doc.qt.io/qt-5/qabstractitemmodeltester.html@mrjj Of course:
Qt::ItemFlags ZauberTableModel::flags(const QModelIndex &index) const { int editspalte = ZauberTableModel::get_spalte_from_header("Beschreibung"); int spalte = index.column(); Qt::ItemFlags f;// = ZauberTableModel::flags(index);; std::cout << "Editierbar " << editspalte << std::endl; if (spalte == editspalte) { f = Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled; } else { f = Qt::ItemIsEnabled; } return f; }So I hope I've boiled down my code to the more relevant parts in my post above.
There's one thing, though, that I forgot to mention. I had to include the cpp file of my subclassed model in order to avoid a linker error after compiling, which is not needed when compiling other examples...
-
@mrjj Of course:
Qt::ItemFlags ZauberTableModel::flags(const QModelIndex &index) const { int editspalte = ZauberTableModel::get_spalte_from_header("Beschreibung"); int spalte = index.column(); Qt::ItemFlags f;// = ZauberTableModel::flags(index);; std::cout << "Editierbar " << editspalte << std::endl; if (spalte == editspalte) { f = Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled; } else { f = Qt::ItemIsEnabled; } return f; }So I hope I've boiled down my code to the more relevant parts in my post above.
There's one thing, though, that I forgot to mention. I had to include the cpp file of my subclassed model in order to avoid a linker error after compiling, which is not needed when compiling other examples...
Hi
it does look fine.did you check that
f = Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
is indeed used for the cells you try to edit ? -
Hi
it does look fine.did you check that
f = Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
is indeed used for the cells you try to edit ?@mrjj Yes, I can double click on the cells and edit them, while double clicking on the others does not work.
I've also tried the test class, but end up with a "undefined reference" error like this:
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: tst_tester.o: in functionZauberTableModel::ZauberTableModel(int, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >, QObject*)': /home/andi/Projekte/qt/build-qtesttest-Desktop-Debug/../qtesttest/zaubertablemodel.cpp:6: undefined reference tovtable for ZauberTableModel'But I'm not sure, if I have setup the test correctly. As I mentioned this also happens, when i just use "#include zaubertablemodel.h" in ui_mainwindow.h. Although I've added the source files to the test project, the above error persists. Somehow the Constructor seems to be undefined.
-
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...