0

I am new to QT. I am trying to create a simple file system browser. I have created a separate class for the model and the view class. Here they are:

//modelClass.h

#ifndef MODELCLASS_H
#define MODELCLASS_H
#include <QFileSystemModel>

class modelClass: public QFileSystemModel{
    Q_OBJECT
public:
    modelClass();  //constructor
    QFileSystemModel* createModel(); //creates the QFileSystemModel
//public slots:
private:
};

#endif // MODELCLASS_H

//modelClass.cpp

#include "modelClass.h"

modelClass::modelClass(){
    createModel();  //calls to function below
}

QFileSystemModel* modelClass::createModel(){
    QFileSystemModel* model = new QFileSystemModel;
    model->setRootPath("/");
    return model;
}

//systemBrowser.cpp

#include "modelClass.h"
#include <QtGui>

int main(int argc, char *argv[]){
    QApplication app(argc, argv);
    modelClass model();

    QTreeView tree;
    tree.setModel(&model);
    tree.setSortingEnabled(true);
    tree.header()->setResizeMode(QHeaderView::ResizeToContents);
    tree.resize(640, 480);
    tree.show();

    return app.exec();
}

Upon trying to compile this, I get the error:

    no matching function for call to 'QTreeView::setModel(modelClass(*)())'
    candidates are: virtual void QTreeView::setModel(QAbstractItemModel*)*

Could anyone please help me with this error? I'm sure its just something simple I am missing. Thank you

1 Answers1

1

Possibly reviving a corpse, I know. But still, this is easy:

The line

modelClass model();

is wrong. Your compiler assumes that this is an forward declaration of a function model() returning the type modelClass. Hence the error in the call to QTreeView::setModel

The line should be written as:

modelClass model;

Also see: http://en.wikipedia.org/wiki/Most_vexing_parse

kfunk
  • 2,002
  • 17
  • 25