1 Qter豆
小弟写了个程序,单独运行时没啥问题,但就是关闭程序后就会出现程序有BUG的提示,如下图:
点OK之后
QT如此显示
我通过注释debug后发现,每当我注释掉这句就没问题 for(i = 0; i < row; i ++) for(j = 0; j < column; j ++) ui->gridLayout->addWidget(blocks + i * row + j, i, j); 复制代码 我在网上查了一堆资料,他们说可能是内存(指针)泄漏问题,但我实在找不出我哪里搞出野指针了,而且我对QT也不熟悉,所以求老师们帮忙看一下
下面是最主要的三个代码文件:class start : public QWidget { Q_OBJECT public: explicit start(Block* blocks, int r, int c, int n, QWidget *parent = 0); ~start(); QTime sysTime; public slots: void timeUpdate(); private slots: void on_startTrip_clicked(); private: int row; int column; int cityNum; Ui::start *ui; }; 复制代码 start::start(Block* blocks, int r, int c, int n, QWidget *parent) : QWidget(parent), ui(new Ui::start) { ui->setupUi(this); row = r; column = c; cityNum = n; int i, j; ui->gridLayout->setSpacing(30); for(i = 0; i < row; i ++) for(j = 0; j < column; j ++) ui->gridLayout->addWidget(blocks + i * row + j, i, j); } start::~start() { delete ui; } 复制代码 int main(int argc, char *argv[]) { QApplication a(argc, argv); //Initializaion int n; Block blocks[ROW * COLUMN]; n = loadMap(blocks, ROW, COLUMN); // Form f; // f.show(); start w(blocks, ROW, COLUMN, n); w.show(); return a.exec(); } 复制代码
我来回答