The problem is solved by erazing some useless lines .
Here is the code:
//header
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
class FenPrincipale
: public QWidget{
Q_OBJECT
public:
FenPrincipale();
bool M[2][2];
private slots:
void FillIn();
private:
};
#endif
//FenPrincipale.cpp
#include <QDebug>
#include "FenPrincipale.h"
FenPrincipale::FenPrincipale()
{
vbox->addWidget(generer);
vbox->addWidget(tabM);
setLayout(vbox);
for (int r = 0; r < tabM->rowCount(); r++) {
for (int c = 0; c < tabM->columnCount(); c++) {
tabM->setItem(r, c, it);
it->setData(Qt::EditRole, 0);
}
}
connect(generer, SIGNAL(clicked()), this, SLOT(FillIn()));
}
void FenPrincipale::FillIn()
{
for (int r = 0; r < tabM->rowCount(); r++) {
for (int c = 0; c < tabM->columnCount(); c++) {
Q_ASSERT(it);
qDebug() << it;
int val = (it->data(Qt::EditRole)).toInt();
M[r][c] = (val == 1) ? true : false;
qDebug() << M[r][c];
}
}
}
//main.cpp
#include <QApplication>
#include "FenPrincipale.h"
int main(int argc, char* argv[])
{
FenPrincipale fenetre;
fenetre.show();
return app.exec();
}
//header
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
class FenPrincipale : public QWidget
{
Q_OBJECT
public:
FenPrincipale();
bool M[2][2];
private slots:
void FillIn();
private:
QTableWidget *tabM;
QPushButton *generer;
};
#endif
//FenPrincipale.cpp
#include <QDebug>
#include "FenPrincipale.h"
FenPrincipale::FenPrincipale()
{
tabM =new QTableWidget(2, 2, this);
generer = new QPushButton("&Générer !",this);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(generer);
vbox->addWidget(tabM);
setLayout(vbox);
for (int r = 0; r < tabM->rowCount(); r++) {
for (int c = 0; c < tabM->columnCount(); c++) {
QTableWidgetItem *it = new QTableWidgetItem;
tabM->setItem(r, c, it);
it->setData(Qt::EditRole, 0);
}
}
connect(generer, SIGNAL(clicked()), this, SLOT(FillIn()));
}
void FenPrincipale::FillIn()
{
for (int r = 0; r < tabM->rowCount(); r++) {
for (int c = 0; c < tabM->columnCount(); c++) {
QTableWidgetItem *it = tabM->item(r,c);
Q_ASSERT(it);
qDebug() << it;
int val = (it->data(Qt::EditRole)).toInt();
M[r][c] = (val == 1) ? true : false;
qDebug() << M[r][c];
}
}
}
//main.cpp
#include <QApplication>
#include "FenPrincipale.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
FenPrincipale fenetre;
fenetre.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Thank you all for your help , I really apreciate it .
Thank you again .
hello,
The problem is solved erazing some useless lines.
Here is the code:
//header
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
class FenPrincipale
: public QWidget{
Q_OBJECT
public:
FenPrincipale();
bool M[2][2];
private slots:
void FillIn();
private:
};
#endif
//FenPrincipale.cpp
#include <QDebug>
#include "FenPrincipale.h"
FenPrincipale::FenPrincipale()
{
vbox->addWidget(generer);
vbox->addWidget(tabM);
setLayout(vbox);
for (int r = 0; r < tabM->rowCount(); r++) {
for (int c = 0; c < tabM->columnCount(); c++) {
tabM->setItem(r, c, it);
it->setData(Qt::EditRole, 0);
}
}
connect(generer, SIGNAL(clicked()), this, SLOT(FillIn()));
}
void FenPrincipale::FillIn()
{
for (int r = 0; r < tabM->rowCount(); r++) {
for (int c = 0; c < tabM->columnCount(); c++) {
Q_ASSERT(it);
qDebug() << it;
int val = (it->data(Qt::EditRole)).toInt();
M[r][c] = (val == 1) ? true : false;
qDebug() << M[r][c];
}
}
}
//main.cpp
#include <QApplication>
#include "FenPrincipale.h"
int main(int argc, char* argv[])
{
FenPrincipale fenetre;
fenetre.show();
return app.exec();
}
//header
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
class FenPrincipale : public QWidget
{
Q_OBJECT
public:
FenPrincipale();
bool M[2][2];
private slots:
void FillIn();
private:
QTableWidget *tabM;
QPushButton *generer;
};
#endif
//FenPrincipale.cpp
#include <QDebug>
#include "FenPrincipale.h"
FenPrincipale::FenPrincipale()
{
tabM =new QTableWidget(2, 2, this);
generer = new QPushButton("&Générer !",this);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(generer);
vbox->addWidget(tabM);
setLayout(vbox);
for (int r = 0; r < tabM->rowCount(); r++) {
for (int c = 0; c < tabM->columnCount(); c++) {
QTableWidgetItem *it = new QTableWidgetItem;
tabM->setItem(r, c, it);
it->setData(Qt::EditRole, 0);
}
}
connect(generer, SIGNAL(clicked()), this, SLOT(FillIn()));
}
void FenPrincipale::FillIn()
{
for (int r = 0; r < tabM->rowCount(); r++) {
for (int c = 0; c < tabM->columnCount(); c++) {
QTableWidgetItem *it = tabM->item(r,c);
Q_ASSERT(it);
qDebug() << it;
int val = (it->data(Qt::EditRole)).toInt();
M[r][c] = (val == 1) ? true : false;
qDebug() << M[r][c];
}
}
}
//main.cpp
#include <QApplication>
#include "FenPrincipale.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
FenPrincipale fenetre;
fenetre.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Thank you all for your help.
I really apreciate it .
Thanks.
Bookmarks