I understand that the correction you suggested corrects the crash on exit, but that's not my problem (it was an error I introduced in the minimum project example and does not affect my full project). The problem is that if I comment this line
lw
->setMovement
(QListView::Snap);
// when this line is commented drag'n'drop does not work on mac, when it is uncommented features 1) and 2) do not work on both win and mac
lw->setMovement(QListView::Snap); // when this line is commented drag'n'drop does not work on mac, when it is uncommented features 1) and 2) do not work on both win and mac
To copy to clipboard, switch view to plain text mode
the drag'n'drop works only on win, while if I uncomment it the drag'n'drop works also on mac, but the two other features described in the original post
1) intercept these internal drag'n'drop events with a slot
2) do operations on the items within the QListWidget in the window destructor before closing the application.
implemented with the following lines of code
// feature 1) intercept drag'n'drop events
connect(model,
&QAbstractItemModel
::rowsMoved,
this,
[=] (const QModelIndex &,
int from,
int,
const QModelIndex &,
int to
) {
qDebug() << "moved item from" << from << "to" << to;
});
// feature 1) intercept drag'n'drop events
QAbstractItemModel * model = lw->model();
connect(model, &QAbstractItemModel::rowsMoved, this, [=] (const QModelIndex &, int from, int, const QModelIndex &, int to)
{
qDebug() << "moved item from" << from << "to" << to;
});
To copy to clipboard, switch view to plain text mode
and
// feature 2) operate on items before closing the application
for (int i = 0; i < items.size(); i++)
{
qDebug() << items[i]->text();
}
// feature 2) operate on items before closing the application
for (int i = 0; i < items.size(); i++)
{
qDebug() << items[i]->text();
}
To copy to clipboard, switch view to plain text mode
cease to work.
Is there anything I can do to get everything working, i.e. reading "moved item from # to #" when an item is moved and reading the list of items' text when I close the application?
Bookmarks