0

I'm trying to write a QListView model and link it to my main UI (from Qt Designer)

here's my main function:

#include "notepad.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Notepad w; w.show(); return a.exec(); } 

and here's my main class Notepad:

Notepad::Notepad(QWidget *parent) : QMainWindow(parent), ui(new Ui::Notepad) { /* some other setup code */ ui->setupUi(this); FileViewModel fileModel(files, 0); ui->listView->setModel(&fileModel); ui->listView->show(); } 

However, the listView doesn't seem to be displaying any elements, whereas I've provided basic functionality in my model.

Any ideas or suggestions?

1
  • The model ceases to exist as soon as the constructor is done with. This is a basic C++ mistake, in the typo category. The answer won't help anyone else. Thus it's offtopic here. Commented Sep 5, 2014 at 20:18

1 Answer 1

1

Try this:

FileViewModel *fileModel = new FileViewModel(files, 0); ui->listView->setModel(fileModel); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.