#include "widget.h"
#include <QAbstractItemModel>
{
this->setGeometry(30,30,800,750);
rank
= new QLineEdit("Enter the Rank",
this);
//rank->setGeometry(10,0,20,20); ok
= new QPushButton("Ok",
this); ok
->setGeometry
(150,
0,
80,
30);
calculate
= new QPushButton("calculate",
this); calculate
->setGeometry
(250,
0,
80,
30);
connect(ok,SIGNAL(clicked()),this,SLOT(ok_clicked()));
connect(calculate,SIGNAL(clicked()),this,SLOT(calculate_clicked()));
}
Widget::~Widget()
{
}
void Widget::ok_clicked()
{
rank_of_Matrix = rank->text().toDouble();
tbl->setGeometry(20,50,770,250);
tbl->show();
}
void Widget::calculate_clicked()
{
tbl_2
= new QTableWidget(rank_of_Matrix,rank_of_Matrix,
this);
tbl_2 ->setGeometry(20,350,770,250);
Action_toArray();
tbl_2 ->show();
}
void Widget::Action_toArray()
{
A= new float* [rank_of_Matrix];
for(int i=0;i<rank_of_Matrix;i++){
A[i]=new float [rank_of_Matrix];
}
//read from Table 1 tbl
for(int i=0;i<rank_of_Matrix;i++){
for(int j=0;j<rank_of_Matrix;j++){
A[i][j] = tbl->item(i,j)-> data(Qt::DisplayRole).toFloat();
}
}
//operation with Array
for(int i=0;i<rank_of_Matrix;i++){
for(int j=0;j<rank_of_Matrix;j++){
if(A[i][j]==2)
{
A[i][j]=0;
}
}
}
//write to Table2 tbl_2
for(int i=0;i<rank_of_Matrix;i++){
for(int j=0;j<rank_of_Matrix;j++){
tableData = A[i][j];
tbl_2->item(i,j)->setData(Qt::EditRole,tableData);
}
}
}
#include "widget.h"
#include <QAbstractItemModel>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->setGeometry(30,30,800,750);
rank = new QLineEdit("Enter the Rank", this);//rank->setGeometry(10,0,20,20);
ok = new QPushButton("Ok", this); ok->setGeometry(150, 0,80,30);
calculate = new QPushButton("calculate",this); calculate->setGeometry(250,0,80,30);
connect(ok,SIGNAL(clicked()),this,SLOT(ok_clicked()));
connect(calculate,SIGNAL(clicked()),this,SLOT(calculate_clicked()));
}
Widget::~Widget()
{
}
void Widget::ok_clicked()
{
rank_of_Matrix = rank->text().toDouble();
tbl=new QTableWidget(rank_of_Matrix,rank_of_Matrix,this);
tbl->setGeometry(20,50,770,250);
tbl->show();
}
void Widget::calculate_clicked()
{
tbl_2 = new QTableWidget(rank_of_Matrix,rank_of_Matrix,this);
tbl_2 ->setGeometry(20,350,770,250);
Action_toArray();
tbl_2 ->show();
}
void Widget::Action_toArray()
{
A= new float* [rank_of_Matrix];
for(int i=0;i<rank_of_Matrix;i++){
A[i]=new float [rank_of_Matrix];
}
//read from Table 1 tbl
for(int i=0;i<rank_of_Matrix;i++){
for(int j=0;j<rank_of_Matrix;j++){
A[i][j] = tbl->item(i,j)-> data(Qt::DisplayRole).toFloat();
}
}
//operation with Array
for(int i=0;i<rank_of_Matrix;i++){
for(int j=0;j<rank_of_Matrix;j++){
if(A[i][j]==2)
{
A[i][j]=0;
}
}
}
//write to Table2 tbl_2
QVariant tableData;
for(int i=0;i<rank_of_Matrix;i++){
for(int j=0;j<rank_of_Matrix;j++){
tableData = A[i][j];
tbl_2->item(i,j)->setData(Qt::EditRole,tableData);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks