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. Problem with printing struc to tableview

Problem with printing struc to tableview

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 945 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sharon_obl82
    wrote on last edited by
    #1

    Hi,
    I can't quite figure out why I'm getting runtime error for this, hopefully someone can shed some light.

    I declare my struc in the header file
    findform.h:
    @
    struct radiofind
    {
    QString rsn;
    int rid;
    QString refID;
    QString secgrp;
    };
    @

    in my cpp file, i have:
    @
    QString radio_rsn;
    QString radio_rid;
    QString radio_rid2;
    QString radio_secgrp;
    QString combo1;
    QString combo2;
    QString combo3;
    int row;
    int col;

    QVector<radiofind> instance;

    Findform::Findform(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Findform)
    {
    ui->setupUi(this);

    radiolist = new QStandardItemModel(0,4,this); //Rows and 4 Columns
    ui->tableView->setModel(radiolist);
    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    radiolist->setHorizontalHeaderItem(0, new QStandardItem(QString(tr("Radio Serial Number"))));
    radiolist->setHorizontalHeaderItem(1, new QStandardItem(QString(tr("Radio ID"))));
    radiolist->setHorizontalHeaderItem(2, new QStandardItem(QString(tr("Radio Reference ID"))));
    radiolist->setHorizontalHeaderItem(3, new QStandardItem(QString(tr("Security Group"))));
    ui->tableView->horizontalHeader()->resizeSection(0,180);
    ui->tableView->horizontalHeader()->resizeSection(1,180);
    ui->tableView->horizontalHeader()->resizeSection(2,180);
    ui->tableView->horizontalHeader()->resizeSection(3,180);
    ui->tableView->setSortingEnabled(true);
    

    // radiofind instance;
    instance[0].rsn = "hello";
    instance[0].rid = 123;
    instance[0].refID = "world";
    instance[0].secgrp = "SYSTEM";
    instance[1].rsn = "A222";
    instance[1].rid = 2222;
    instance[1].refID = "AA2222";
    instance[1].secgrp = "SYSTEM";
    instance[2].rsn = "A3333";
    instance[2].rid = 3333;
    instance[2].refID = "Test";
    instance[2].secgrp = "PRIVATE";

            // For test - start
                                 row = 0;
                                 radiolist->insertRow(row);
                                 col = 0;
                                 radiolist->setData(radiolist->index(row,col),instance[0].rsn);
                                 radiolist->setData(radiolist->index(row,++col),instance[0].rid);
                                 radiolist->setData(radiolist->index(row,++col),instance[0].refID);
                                 radiolist->setData(radiolist->index(row,++col),instance[0].secgrp);
    
                                 row = 1; col = 0;
                                 radiolist->insertRow(row);
    
                                 radiolist->setData(radiolist->index(row,col),instance[1].rsn);
                                 radiolist->setData(radiolist->index(row,++col),instance[1].rid);
                                 radiolist->setData(radiolist->index(row,++col),instance[1].refID);
                                 radiolist->setData(radiolist->index(row,++col),instance[1].secgrp);
    
                                 row = 2; col = 0;
                                 radiolist->insertRow(row);
    
                                 radiolist->setData(radiolist->index(row,col),instance[2].rsn);
                                 radiolist->setData(radiolist->index(row,++col),instance[2].rid);
                                 radiolist->setData(radiolist->index(row,++col),instance[2].refID);
                                 radiolist->setData(radiolist->index(row,++col),instance[2].secgrp);
    
                                 // For test - end
    

    }
    @

    The code compiles successfully but when i click on the form to load the data into the table, i get this error:
    Invalid parameter passed to C runtime function.
    ASSERT failure in QVector<T>::operator[]: "index out of range", file ....\5.2.1\mingw48_32\include/QtCore/qvector.h, line 369
    Invalid parameter passed to C runtime function.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      radiolist = new QStandardItemModel(0,4,this);

      You have created model with zero rows. At line 55 and 63 you are setting the row=1 and row=2. So you are inserting at row 1 and 2. You radioList does not have those rows.

      You can initialize this.

      radiolist = new QStandardItemModel(10,4,this); If you want 10 rows. I have just taken the example of 10 rows.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      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