Hello:
I have the following code that generates the following User Interface Attachment 7028
Basically its a QDIalog encapsualting 2 QPushButtons and a class derived from QTableWidget. The ADDROW button adds rows. Each row is comprised of 4 fielsd, a checkbox, a combobox and text for the remainder of the tqo. The corresponding code is spread out in the following 4 files.
Code:
# ifndef __MTBL__ # define __MTBL__ # include <QTableWidget> # include <QPushButton> # include <QComboBox> # include <QDialog> # include <QCheckBox> { Q_OBJECT public: myTable(); public slots: void addCustomRow(); void removeCustomRow(); }; # endif
This is the corresponding source file. myTable.cpp
This is the dialog file which encapsulates myTable and the two buttons.Code:
# include "myTable.h" # include <QMessageBox> myTable::myTable() { this->setRowCount(0); this->setColumnCount(4); }; void myTable::addCustomRow() { int row = this->rowCount(); this->insertRow(row); q->setText("here"); q->show(); mBox->show(); mBox->addItem("Hello"); mBox->addItem("World"); mBox->show(); mCheck->setChecked(false); mCheck->show(); this->setCellWidget(row,0,mCheck); this->setCellWidget(row,1,mBox); }; void myTable::removeCustomRow() { int numRows = this->rowCount(); for ( int i = 0 ; i < numRows ; i++) { if (mBox->isChecked()) { this->removeRow(i); } } }
Code:
# ifndef __MDLG__ # define __MDLG__ # include <QTableWidget> # include <QPushButton> # include <QComboBox> # include <QDialog> # include "myTable.h" { Q_OBJECT public: myTable * mTable; QPushButton * mAddButton; QPushButton * mRemoveButton; myDialog(); }; # endif
Code:
# include "myDialog.h" # include <QVBoxLayout> myDialog::myDialog() { this->mTable = new myTable(); this->mTable->show(); this->mAddButton->show(); this->mRemoveButton->show(); mLay->addWidget(this->mAddButton); mLay->addWidget(this->mRemoveButton); mLay->addWidget(this->mTable); this->connect(this->mAddButton,SIGNAL(clicked()),this->mTable,SLOT(addCustomRow())); this->connect(this->mRemoveButton,SIGNAL(clicked()),this->mTable,SLOT(removeCustomRow())); this->setLayout(mLay); this->show(); };
The problem is with the removeCustomRow () slot in myTable.cpp. Whenever I select a checkbox in the UI above and hit "Remove Row" button the application crashes. I put in debugging code and found that the loop in the removeCUstomRow () function tends to remove all the rows (even if they are not checked) and then crashes.
The above code is standalone so you can copy and paste it in you ide and see its behavior.
Just include the files and instantiate myDIalog between QApplication a(argc,argv) and app.exe and you will be able to replicate the problem at your end.
Any help would be appreciated.
