Program crash with ui->listView->setModel()

  • 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 =;
                QString filenameNoExt = filenameRaw.split(".", QString::SkipEmptyParts).at(0);
                QString filename = filenameNoExt.split("/", QString::SkipEmptyParts).at(3);
                qDebug() << filename;
                fileList << filename;
                QStringListModel *model = new QStringListModel();
                qDebug() << fileList;
                //Problematic Line (everything works as intended until here)

  • Qt Champions 2017

    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();
       //Problematic Line (everything works as intended until here)

  • @mrjj

    ROFL! The function call was before setupUI ^.^ I'll see if that fixes it :P

    Edit: Yep! That was the problem :P My bad! Thanks for the help!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.