Program crash with ui->listView->setModel()
Solved
General and Desktop
-
Noob question :D
I am trying to populate a QListView with the data from a StringList, however the program crashes if I un-comment the last line. I suspect it's a wayward pointer (probably ui->listView).QStringList fileList; // Remove file extension and absolute path from string respectively (to be replaced by QFileInfo) QString filenameRaw = it.next(); QString filenameNoExt = filenameRaw.split(".", QString::SkipEmptyParts).at(0); QString filename = filenameNoExt.split("/", QString::SkipEmptyParts).at(3); qDebug() << filename; fileList << filename; QStringListModel *model = new QStringListModel(); model->setStringList(fileList); qDebug() << fileList; //Problematic Line (everything works as intended until here) ui->listView->setModel(model);
-
Hi and welcome
I tried your code in a new project with a QListView on the form
and got abfdef and no crashes.
So where do you call your code?
its after setupUI, yes?void MainWindow::on_pushButton_released() { QStringList fileList; fileList << "a" << "b" << "c"<< "d"<< "f"; QStringListModel* model = new QStringListModel(); model->setStringList(fileList); //Problematic Line (everything works as intended until here) ui->listView->setModel(model); }