I have always been very happy with Qt's documentation, but when I tried to use QDataWidgetMapper I was a bit disappointed. Is this just supposed to work by magic? It doesn't do that here...
I have a QTableView with a QAbstractTableModel derived vertical model with four columns. This works very nicely and I can view and edit rows in the table view.
I also have a dock widget with some line edits as an alternative way to edit the fields. These fields are the one I have used a QDataWidgetMapper for. The problem is just that it doesn't work. When I select a row and edit it in the dock window, the table is updated, but not the other way around. The fields in the dock widget aren't filled at all when I change the selected row in the table view. *Something* is happening when I change the select row though, because when I submit the text from the dock widget edits the correct row is updated.
The code:
mapper->setModel(model);
mapper->addMapping(lineEdit1, 0);
mapper->addMapping(lineEdit2, 1);
mapper = new QDataWidgetMapper();
mapper->setModel(model);
mapper->addMapping(lineEdit1, 0);
mapper->addMapping(lineEdit2, 1);
connect(view->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), mapper, SLOT(setCurrentModelIndex(QModelIndex)));
To copy to clipboard, switch view to plain text mode
view is a pointer to the table view, model is a painter to the model I use.
What did I forget to do?
Bookmarks