@Sikarjan-0 said in Working with a QListView crashes with no error:
why do I have to put mModel = new QStringListModel(...); prior mModel->setStringList? Is declaring it in the header not enough?
No, it is not enough! You should take some time to understand this, you will need to in order to program in C++ successfully.
Note that you are declaring a pointer to a QStringListModel when you write QStringListModel *mModel;. Your class will indeed have room for that pointer allocated, but it does not point to any QStringListModel when an instance of your class is created. If you are "lucky" (not really!) it is set to nullptr, if you are "unlucky" (much more likely for class members) the pointer has a garbage value. Either way if you try to do anything with mModel-> --- which mModel->setStringList() will be doing --- something "bad" will happen! In the constructor of the class you are likely to want to create the model instance with mModel = new QStringListModel(this), now you have allocated a model and set mModel to point to it.
Note this is very different from having your class member variable declared via QStringListModel mModel;. This is not a pointer to an instance of QStringListModel, which needs to be allocated, it is an actual instance of a QStringListModel, which is created as your instance is created. Which of these two you want/prefer depends on your code.