Nominate our 2022 Qt Champions!

Can't create QStandardItem and display it in a QTableView

  • Hi all,

    I'm converting an old program into c++ and is using Qt as my main tool for the UI.
    Now my problem is that I have data on a binary file, written struct of data that I want to display and in some cases edit. Text is no problem however when it comes to numeric values it's a no go.

    The below code works and contain data but crashes on first attempt to create the timestamp item with a "SIGSEV" and "Segmentation fault" error displayed. If I change the long timestamp into a string it works
    Any ideas?

        struct data{
           long timestamp;
           long ar [20];
           QString name;
    int convert( int noOfData)
      struct data buf [20];
      int pos = 0;
      QList<QStandarItem *> items;
      QStandardItemModel *model = new QStandardItemModel();
      // read data to buf from disc in a for-loop.
      // then insert into an item and add to the modell
      for(int i = 0; i < noOfData; i++)
             lseek(filehandle,  i * sizeof(struct data), 0 );
             read(filehandle, &buf[i], sizeof(struct data));
             items.append(new QStandardItem(buf[i].timestamp));
             for(int j = 0; j < 20; j++)
                items.append((new QStandardItem(buf[i].ar[j]));
             items.append(new QStandardItem(buf[i].name));

  • Lifetime Qt Champion


    What does the debugger tell you about it ?

  • @SGaist Hi, nothing, it compiles ok and runs.
    The only closest thing is a flaw in my fix, though just a warning
    And when it crashes, nothing as far as I can tell or find.