I modified my dialog but my program keeps crashing and I don't find the root cause.
My application is defined as follows:
there are 3 classes:
Dummy, Coordinator and MatrixDialog
Dummy performs computation to generate the matrix I need. This matrix is then sent to the Coordinator which forwards it to the MatrixDialog.
here is the code of MatrixDialog:
matrixDialog.h
class MatrixDialog
: public QDialog { Q_OBJECT
public:
void updateTable(QStringList& strings, SquareMatrix& matrix);
private slots:
void ok();
private:
};
class MatrixDialog : public QDialog {
Q_OBJECT
public:
MatrixDialog(QString windowTitle, QWidget *parent = 0);
void updateTable(QStringList& strings, SquareMatrix& matrix);
private slots:
void ok();
private:
QTableWidget *matrixTable;
};
To copy to clipboard, switch view to plain text mode
matrixDialog.cpp
#include "matrixDialog.h"
this->matrixTable->horizontalHeader()->setStretchLastSection(true);
this->matrixTable->verticalHeader()->setStretchLastSection(true);
formatLayout->addWidget(mapleLabel);
formatLayout->addWidget(mapleEdit);
okButton->setFixedSize(okButton->size());
connect(okButton, SIGNAL(clicked()), this, SLOT(ok()));
mainLayout->addWidget(matrixTable);
mainLayout->addWidget(okButton);
setLayout(mainLayout);
setWindowTitle(windowTitle);
}
void MatrixDialog::ok() {
this->hide();
}
void MatrixDialog::updateTable(QStringList& tickers, SquareMatrix& matrix) {
int dimension = matrix.getDimension();
double value;
this->matrixTable->clear();
this->matrixTable->setRowCount(matrix.getRows());
this->matrixTable->setColumnCount(matrix.getColumns());
for(int row = 0; row < dimension; ++row) {
matrixTable->setHorizontalHeaderItem(row, headerItem);
matrixTable->setVerticalHeaderItem(row, headerItem);
for(int column = 0; column < dimension; ++column) {
matrix.getElement(row, column, value);
item->setTextAlignment(Qt::AlignCenter);
this->matrixTable->setItem(row, column, item);
}
}
}
#include "matrixDialog.h"
MatrixDialog::MatrixDialog(QString windowTitle, QWidget *parent) : QDialog(parent) {
this->matrixTable = new QTableWidget(this);
this->matrixTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
this->matrixTable->horizontalHeader()->setStretchLastSection(true);
this->matrixTable->verticalHeader()->setStretchLastSection(true);
QHBoxLayout *formatLayout = new QHBoxLayout;
formatLayout->addWidget(mapleLabel);
formatLayout->addWidget(mapleEdit);
QPushButton *okButton = new QPushButton("OK");
okButton->setFixedSize(okButton->size());
connect(okButton, SIGNAL(clicked()), this, SLOT(ok()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(matrixTable);
mainLayout->addWidget(okButton);
setLayout(mainLayout);
setWindowTitle(windowTitle);
}
void MatrixDialog::ok() {
this->hide();
}
void MatrixDialog::updateTable(QStringList& tickers, SquareMatrix& matrix) {
int dimension = matrix.getDimension();
double value;
this->matrixTable->clear();
this->matrixTable->setRowCount(matrix.getRows());
this->matrixTable->setColumnCount(matrix.getColumns());
for(int row = 0; row < dimension; ++row) {
QTableWidgetItem *headerItem = new QTableWidgetItem(tickers.at(row));
matrixTable->setHorizontalHeaderItem(row, headerItem);
matrixTable->setVerticalHeaderItem(row, headerItem);
for(int column = 0; column < dimension; ++column) {
matrix.getElement(row, column, value);
QTableWidgetItem *item = new QTableWidgetItem(QString::number(value));
item->setTextAlignment(Qt::AlignCenter);
this->matrixTable->setItem(row, column, item);
}
}
}
To copy to clipboard, switch view to plain text mode
When the Coordinator calls updateTable of MatrixDialog, the application crashes. I even deleted all updateTable's content, but the application still crashes !
Coordinator is defined as follows:
class Coordinator
: public QObject { Q_OBJECT
...
};
class Coordinator : public QObject {
Q_OBJECT
...
};
To copy to clipboard, switch view to plain text mode
I'm lost...I just don't understand how I can do an unauthorized access... I would really appreciate some help !
Thanks guys in advance for your support
Bookmarks