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. Can't create QStandardItem and display it in a QTableView
Forum Update on Monday, May 27th 2025

Can't create QStandardItem and display it in a QTableView

Scheduled Pinned Locked Moved General and Desktop
qtableviewqstandarditemqt5.2
3 Posts 2 Posters 1.3k 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.
  • A Offline
    A Offline
    andsun
    wrote on last edited by
    #1

    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.clear();
             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));
      }
    }
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What does the debugger tell you about it ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What does the debugger tell you about it ?

        A Offline
        A Offline
        andsun
        wrote on last edited by andsun
        #3

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

        1 Reply Last reply
        0

        • Login

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