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. Qtablewidget Throwing Segmentation Fault
Forum Updated to NodeBB v4.3 + New Features

Qtablewidget Throwing Segmentation Fault

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.0k 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.
  • T Offline
    T Offline
    tan3587
    wrote on last edited by
    #1

    I am using QtableWidget to populate data collected from ROS messages:

    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->st
    at->setItem(count_row,2,text);
    count_row++;
    for(int i=4;i>=0;i--)
    ui->stat->showRow(i);

    On running the program, I am getting segmentation fault error. Please help!!

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      1. Do you want to display any text in QTableWidget ? As i can see you have not added any text to your QTableWidgetItem.

      2. You are adding 3 items in 1st row's 3 columns and you are iterating the whole QTableWidget. And here no need to do showRow as the items will be displayed by default when you set text to it.

      3. I modified your code as follows and i see no crashes:
        @ui->stat->setColumnCount(3);
        ui->stat->setRowCount(5);
        int 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();
        text->setText("Sometext");
        QTableWidgetItem* msgType = new QTableWidgetItem();
        msgType->setText("SomeMessage");
        QTableWidgetItem* time = new QTableWidgetItem();
        time->setText("SomeTime");

        count_row=count_row%5;
        qDebug() << count_row;
        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);@

      4. Please include your code in Code tags as it is difficult to understand to others.

      157

      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