Pregunta

I am migrating a project from Qt 4.x to 5, and the next function is obsolete:

model->setSupportedDragActions(Qt::MoveAction);

I have researched and apparently I have to reimplement the function / override a virtual one called supportedDragActions() This guy had the same problem with the function and solved it. My newbie question is, where should I reimplement such function? in the qabstractitemmodel.h/cpp? or somewhere in another class?

Forgive my ignorance.

Thankyou.

EDIT: I implemented the function in my cpp, right above the function that calls setSupportedDragActions(), like this:

mapmodulelist.cpp:
void QAbstractItemModel::setSupportedDragActions(Qt::DropActions actions){
    Q_D(QAbstractItemModel);
    d->supportedDragActions = actions;
}

void MapModuleList::setupModel() {
    if (mapLayersModel == NULL) {
        mapLayersModel = new QStandardItemModel(0);
        mapLayersModel ->setSupportedDragActions(Qt::MoveAction);
    }
}

mapLayersModel is a member of this class, this is its declaration:

static QStandardItemModel* mapLayersModel;

I also had to add a header to qabstractitemmodel.h:

void setSupportedDragActions(Qt::DropActions actions);

I get the next errors:

invalid use of incomplete type 'class QAbstractItemModelPrivate'
     d->supportedDragActions = actions;
      ^

and

forward declaration of 'class QAbstractItemModelPrivate'
 class QAbstractItemModelPrivate;
       ^

I must be doing something wrong.

¿Fue útil?

Solución

You need to implement (rather override) this virtual function in your model subclass, i.e. in the same class where you implemented the obsolete setSupportedDragActions() function. This only necessary if you need drag and drop functionality for your views.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top