Qt4 SegmentationFault on QTableWidget::setItem
Qt4 SegmentationFault on QTableWidget::setItem
我这里有一个非常奇怪的问题。我的程序是SegmentationFault
,当我在表中设置项目时。这是我的代码。
class Program : public QMainWindow {
Q_OBJECT
public:
Program();
private:
QTableWidget *table;
private slots:
void newSlot();
}
Cpp文件:
Program::Program() : QMainWindow() {
....
....
....
....
table = new QTableWidget();
table->setRowCount( 0 );
table->setColumnCount( 2 );
....
....
....
}
void Program::newSlot() {
....
....
....
table->insertRow( table->rowCount() );
table->setItem( table->rowCount() - 1, 0, new QTableWidgetItem( "something" ) );
table->setItem( table->rowCount() - 1, 1, new QTableWidgetItem( "something" ) );
....
....
....
}
问题是当程序在newSlot()
中达到table->setItem( ... )
时,我得到了分割故障。我是不是在什么地方犯了愚蠢的错误,导致了这一团糟?因为我在其他地方使用了完全相同的代码,没有任何问题。
必须指定列数:
table->setColumnCount( 2 );
做table->setItem( table->rowCount() - 1, 0, new QTableWidgetItem( "something" ) );
...
相关文章:
- 当用户在qtablewidget中输入单元格时,如何获得信号?C++
- C++,Qt:仅在双击后编辑qtablewidget项目
- QTableWidget 到多个文件
- PyQT - 在 QTableWidget 单元格中显示垂直文本
- 检测是否在 QTableWidget 中添加或删除了列
- 如何填写 QTableWidget?
- QTableWidget一次显示一定数量的行
- QTableWidget省略了一些主题,项目被创建但被忽略
- 如何为 QTableWidget 添加自动完成
- 使用鼠标滚轮平滑地滚动QTableWidget
- 使用连接更新 QtableWidget
- 将 QTableWidget 内容打印为 PDF
- 如何插入额外的 QTableWidget
- 如何通过 Qdialog 中的 qtablewidget 填充作为 MainWindow 成员的 qvector
- QTableWidget dataChanged SIGNAL
- 如何通过 CTRL+单击在 QTableWidget 中禁用多个项目选择
- Qt C++ - 删除 QTableWidget 中的行
- 如何在可滚动的 QTableWidget 中有一个冻结的水平标题?
- Qt Segmentation Fault QTableWidget->SetItem(int,int,QTableWidgetItem)
- Qt4 SegmentationFault on QTableWidget::setItem