Qtablewidget投掷分段错误

时间:2013-09-18 02:27:09

标签: qt segmentation-fault qtablewidget ros

我正在使用QtableWidget来填充从ROS消息中收集的数据:

ui->stat->setColumnCount(3);
    //ui->stat->setRowCount(5);
    count_row=0;// keep track of table rows
    ui->stat->setColumnWidth(0,145);
    ui->stat->setColumnWidth(1,50);
    ui->stat->setColumnWidth(2,300);
QStringlist labels;
    labels.push_back(" Time");
    labels.push_back("Type");
    labels.push_back("Message ");
    ui->stat->setHorizontalHeaderLabels(labels);
QTableWidgetItem* text = new QTableWidgetItem();
       QTableWidgetItem* msgType = new QTableWidgetItem();
       QTableWidgetItem* time = new QTableWidgetItem();
count_row=count_row%5;
ui->stat->setItem(count_row,0,time);
      ui->stat->setItem(count_row,1,msgType);
      ui->stat->setItem(count_row,2,text);
      count_row++;
      for(int i=4;i>=0;i--)
           ui->stat->showRow(i);

运行程序时,我收到分段错误错误

1 个答案:

答案 0 :(得分:0)

要使用setItem(row, col, text),您需要设置行数(此行://ui->stat->setRowCount(5);),或者,如果您不知道您将拥有多少行,则可以使用 insertRow(count_row)之后设置该行的项目。