Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. QTableWidget中内容为空的时候访问数据,则会造成异常退出
Forum Updated to NodeBB v4.3 + New Features

QTableWidget中内容为空的时候访问数据,则会造成异常退出

Scheduled Pinned Locked Moved Chinese
1 Posts 1 Posters 1.9k 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
    tsuibin
    wrote on last edited by
    #1

    使用UI设计工具画一个QTableWidget,然后在编辑控件,添加行和列

    完成后访问表格数据(当表格内容为空的时候,则会异常退出)

    测试代码

    void WebSubmitTool::on_pushButton_testData_clicked()
    {

    int row = ui->tableWidget_get->rowCount();
    int column = ui->tableWidget_get->columnCount();
    
    qDebug() <<"row/column:" << row <<"/"<< column;
     QTableWidgetItem *item;
    for(int i = 0;i < row; i++)
    {
        for(int x = 0; x < column; x++)
        {
            qDebug() <<"key/value:"<<i << x;
            item = ui->tableWidget_get->item(i,x);
            qDebug()<<item->text();
    
        }
    
    }
    

    }

    执行到 qDebug()<<item->text(); 则异常退出

    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