Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Program crash with ui->listView->setModel()

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

Scheduled Pinned Locked Moved Solved General and Desktop
listviewqt 5.5modelcrashes
3 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    htmlboss
    wrote on 6 Dec 2015, 18:26 last edited by
    #1

    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);
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 6 Dec 2015, 18:39 last edited by mrjj 12 Jun 2015, 18:39
      #2

      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);
      }
      
      H 1 Reply Last reply 6 Dec 2015, 19:14
      1
      • M mrjj
        6 Dec 2015, 18:39

        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);
        }
        
        H Offline
        H Offline
        htmlboss
        wrote on 6 Dec 2015, 19:14 last edited by htmlboss 12 Jun 2015, 19:20
        #3

        @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!

        1 Reply Last reply
        1

        1/3

        6 Dec 2015, 18:26

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved