Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:52:31+00:00 2026-06-12T16:52:31+00:00

In qt, I use tablewidget to store 100 rows. At first, I new tableWidgetItems

  • 0

In qt, I use tablewidget to store 100 rows. At first, I new tableWidgetItems to fill the rows.
As it runs, I set the items’ propertities and no longer ‘new’.
But I find after I use ‘ui->tableWidget->setRowCount(index);’, and later set back to 100, the code “ui->tableWidget->item(index, 0)->setText(…);” will crash the program. That’s so bad!!! ;(
I debugged and find the new index > index set as row count before ‘setting back to 100’.

Did the system delete the table items automatically when I set smaller row count???

I fear about this so much because even my code cannot determine the lifetime of the objects I created… Does anyone know how to keep them ‘alive’ after setting row count?(otherwise, I have to new them…).
I really appreciate it you take the patience to read my poor ELis:)

new:

//TABLE
    ui->tableWidget->setColumnCount(3);
    ui->tableWidget->setRowCount(100);
    ui->tableWidget->setHorizontalHeaderLabels(headers);

    for(int i = 0; i < 100; i++)//new
    {
        ui->tableWidget->setItem( i, 0 , new QTableWidgetItem(""));//time
        ui->tableWidget->setItem( i, 1 , new QTableWidgetItem(""));//name
        ui->tableWidget->setItem( i, 2 , new QTableWidgetItem(""));//BITS
    }

Related code lines only:

   {
    int  index = 0;
    for(int queue_i = size_1; queue_i >= 0; queue_i--)
    {


        if(logDisplayQueue.at(queue_i).at(3) == "0" ||   logDisplayQueue.at(queue_i).at(3) == "2")continue;


        QStringList BITList = bits2Hexs(queue_i);


     ui->tableWidget->item(index, 0)->setText(logDisplayQueue.at(queue_i).at(0));//time
     ui->tableWidget->item(index, 1)->setText(logDisplayQueue.at(queue_i).at(1));//name
     ui->tableWidget->item(index, 2)->setText(BITList.join(""));//BITS

        if(queue_i == oldRowItemNo)ui->tableWidget->selectRow(index);
        index++;
    }

        ui->tableWidget->setRowCount(index);//set row count to be 30 more or less
    }

Another function:

    {

        ui->tableWidget->setRowCount(100);//back to be 100 again


        for(int queue_i = size_1, index = 0; queue_i >= 0; queue_i--, index++)
        {

            QStringList BITList = bits2Hexs(queue_i);
     ui->tableWidget->item(index, 0)->setText(logDisplayQueue.at(queue_i).at(0));//time
     ui->tableWidget->item(index, 1)->setText(logDisplayQueue.at(queue_i).at(1));//name
     ui->tableWidget->item(index, 2)->setText(BITList.join(""));//BITS
//In debugging, when index reches the value of old row-count, "->setText" crashes the    //program.


            if(queue_i == oldRowItemNo)ui->tableWidget->selectRow(index);
        }

    }

When running, it returns message like ‘instruction 0x00421727 refers to 0x00000000 memory, the memory cannot be ‘read”

if I comment off this line:
‘ui->tableWidget->setRowCount(index);//set row count to be 30 more or less’, it runs well without crash and rows after index-referred-row show the same data as before.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:52:32+00:00Added an answer on June 12, 2026 at 4:52 pm

    setRowCount ensures that the table holds exactly that many rows. If you had more rows than index before, those rows are gone (deleted).

    If you want to temporarily hide rows, you should probably use hideRow(int)/showRow rather than resetting the row count.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used to use : tabHost.getTabWidget().getChildAt(0).getLayoutParams().height =50; to set my tab height. But I
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );
I want to use tabs but it don't work. Here my .java codes :
use Parallel::ForkManager; use LWP::Simple; my $pm=new Parallel::ForkManager(10); our $a =0; @LINK=( 10,203, 20, 20
I am trying to use tabs with a webview but I cant seem to
I want to use more than one CheckBox in each tab, but only one
QTableWidget::setItemPrototype says following. The table widget will use the item prototype clone function when
Use Case Show a photo uploaded by the user in a square box with
use C#,want to upload excel file on google doc. bellow syntax use to upload
use strict; use warnings; use Time::HiRes qw(sleep); use Test::WWW::Selenium; use Test::More no_plan; use Test::Exception;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.