Hello everyone,
I’m trying to fill a QTablewidget with matrix of vectors, I have the following code. I’m sure that my Qt code is good but I don’t know my it doesn’t work. Is there something I missed out?
I would really appreciate your help!
#include "qtablewidget.h"
#include <vector>
class Test
{
public:
Test(){};
MainClass obj;
void setMatrix(std::vector<std::vector<double>> a){
obj.GetMatrix(a);
}
void createMatrix(){
/*
/ some code to fill the private variable matrix;
*/
this->setMatrix(this->matrix);
}
private:
std::vector<std::vector<double>> matrix;
}
class MainClass : public QMainWindow
{
Q_OBJECT
public:
MainClass(QWidget *parent = 0, Qt::WFlags flags = 0);
void GetMatrix(std::vector<std::vector<double>> p){
this->widget.tableWidget->setRowCount(p.size());
this->widget.tableWidget->setColumnCount(p[0].size());
for(unsigned int row=0;row<p.size();row++){
for(unsigned int column=0;column<p[0].size();column++){
QTableWidgetItem* newItem = new QTableWidgetItem();
newItem->setText(QString::number(p[row][column]));
this->widget.tableWidget->setItem(row,column,newItem);
}
}
}
private:
Ui::MainClass widget;
}
↧