PDA

View Full Version : create a QDialog from a QDialog



hichemnho
27th February 2012, 10:05
Hello everyone ,
I would like to create a "FenCC"(QDialog) window after clicking the "Composantes" button but I tried and it does not work .
Here is the Description :
1-I fill the QTableWidget
2-I click on the button "Generer"
3-the array M is filled by the value in the QTableWidget
4-I click on "Dessiner" button
5-Creation of a QDialog whose type is "FenDessin"
6-I click on the "Composantes" button
7-création of a QDialog whose type is "FenCC"

It is the points 6 et 7 that do not work but the points 1, 2 , 3 , 4 , 5 work .

Here is the code:



//FenPrincipale.h
//FenPrinicipale.h
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>

class FenPrincipale : public QWidget
{
Q_OBJECT
public:
FenPrincipale();
bool M[10][10];

private slots:
void FillIn();
void FenetreDessin();
private:
QTableWidget *tabM;
QPushButton * generer;
QPushButton * dessiner;
QVBoxLayout * vbox;

};
#endif // FENPRINCIPALE_H

//FenPrincipale.cpp

//FenPrincipale.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
FenPrincipale::FenPrincipale()
{
tabM =new QTableWidget(this);
tabM->setRowCount(10);
tabM->setColumnCount(10);
generer = new QPushButton("&Générer !",this);
dessiner = new QPushButton("&Dessiner !",this);

QVBoxLayout* vbox = new QVBoxLayout();
vbox->addWidget(generer);
vbox->addWidget(dessiner);
vbox->addWidget(tabM);
this->setLayout(vbox);
for (int r = 0; r < 10; r++) {
for (int c = 0; c < 10; 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 < 10; r++) {
for (int c = 0; c < 10; 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];
}
}
connect(dessiner, SIGNAL(clicked()), this, SLOT(FenetreDessin()));
}
void FenPrincipale::FenetreDessin()
{
FenDessin *fenetreC = new FenDessin(this);
fenetreC->setFixedSize(950,900);
fenetreC->show();
}


//FenDessin.h
//FenDessin.h
#ifndef FENDESSIN_H
#define FENDESSIN_H
#include <QtGui>
#include"FenPrincipale.h"
class FenDessin : public QWidget
{
public:
FenDessin ( FenPrincipale* parent);
private:
QPushButton *Composante;
QPainter *painter;
FenPrincipale * ref;
private slots:
void paintEvent (QPaintEvent *);
void CC ();
};
#endif // FENDESSIN_H

//FenDessin.cpp
#include "FenDessin.h"
#include "FenPrincipale.h"
#include "FenCC.h"
FenDessin::FenDessin( FenPrincipale *parent) :QDialog(parent),ref(parent)
{
Composante = new QPushButton("Composante",this);
QPaintEvent *c=NULL;
paintEvent(c);

connect(Composante, SIGNAL(clicked()), this, SLOT(CC()));

}

void FenDessin::paintEvent(QPaintEvent *c)
{
QPainter painter(this);


int tour=0;
int x=10;
int y=10;
int Num_Sommet=0;
int T_Coordonnees [10][3];
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
(T_Coordonnees[Num_Sommet][0])=x;
(T_Coordonnees[Num_Sommet][1])=y;
(T_Coordonnees[Num_Sommet][2])=tour;

if (tour==0)
{
x+=35;
tour=1;
}
else
{
y+=55;
tour=0;
}

}

int w1=0;
int w2=0;
int cpt=10;
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
if ( (T_Coordonnees[Num_Sommet][2])==1)
{ if(w1==0)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+500) ;
w1=1;
}
else
{
if(w1==1)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+250+cpt) ;
w1=0;
cpt=cpt+15;
}
}
if (Num_Sommet==9)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}

}
else
{
if(w2==0)
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+200;
w2=1;
}
else
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+100+cpt;
w2=0;
cpt=cpt+15;
}

if (Num_Sommet==4)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}
}
painter.drawEllipse((T_Coordonnees[Num_Sommet][0]), (T_Coordonnees[Num_Sommet][1]), 30.0, 30.0);
}

int i,j;
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j])==1)
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
}
}
}



for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j]==1) && (ref->M[j][i]==1))
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
if( (T_Coordonnees[i][1]>45)||(T_Coordonnees[j][1]>45) )
{
painter.drawLine(((T_Coordonnees[i][0]+20)-10),(T_Coordonnees[i][1]),((T_Coordonnees[j][0]+20)-10),(T_Coordonnees[j][1]));
}
else
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]+30),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]+30));
}
}
}
}
////////////////////////////////////////////////
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
QPoint point = QPoint( (((T_Coordonnees[Num_Sommet][0])+15)), ((T_Coordonnees[Num_Sommet][1])+15) );
QString str;
str.setNum(Num_Sommet);
painter.drawText( point,str);

}
}
void FenDessin::CC()
{

FenCC *fenetreCC = new FenCC(this);
fenetreCC->setFixedSize(900,900);
fenetreCC->show();
}
//FenCC.h
#ifndef FENCC_H
#define FENCC_H
#include <QtGui>
class FenCC : public QDialog
{
public:
FenCC ( QDialog *parent);
private:
QPushButton *fermer;
private slots:
};
#endif

//FenCC.cpp

#include "FenCC.h"
FenCC::FenCC( QDialog *parent = 0) :QDialog(parent)
{
fermer = new QPushButton("Fermer",this);

connect(fermer, SIGNAL(clicked()), this, SLOT(accept()));

}


//main.cpp

#include <QApplication>
#include "FenPrincipale.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
FenPrincipale fenetre;
fenetre.show();
return app.exec();
}




Thank you in advance for your attention and help.

mentalmushroom
27th February 2012, 14:03
Your code gives a compilation error at following lines:

FenDessin::FenDessin( FenPrincipale *parent) :QDialog(parent),ref(parent)

FenCC *fenetreCC = new FenCC(this);

Your class FenDessin is actually QWidget, not QDialog. Look at FenDessin.h.

5-Creation of a QDialog whose type is "FenDessin"

hichemnho
27th February 2012, 14:35
Thank you very much for your answer,


I 've modified it but it is still not working.



//FenCC.h
#ifndef FENCC_H
#define FENCC_H
#include <QtGui>
#include "FenDessin.h"
#include "FenPrincipale.h"
#include "FenCC.h"
class FenCC : public QDialog
{
public:
FenCC ( QDialog *parent);
private:
QPushButton *fermer;
private slots:
};
#endif



//FenDessin.h
#ifndef FENDESSIN_H
#define FENDESSIN_H
#include <QtGui>
#include "FenDessin.h"
#include "FenPrincipale.h"
#include "FenCC.h"
class FenDessin : public QDialog
{
public:
FenDessin ( FenPrincipale *parent);
private:
QPushButton *Composante;
QPainter *painter;
FenPrincipale *ref;
private slots:
void paintEvent (QPaintEvent *);
void CC ();
};
#endif // FENDESSIN_H



//FenPrinicipale.h
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
#include "FenDessin.h"
#include "FenPrincipale.h"
#include "FenCC.h"
class FenPrincipale : public QWidget
{
Q_OBJECT
public:
FenPrincipale();
bool M[10][10];

private slots:
void FillIn();
void FenetreDessin();
private:
QTableWidget *tabM;
QPushButton * generer;
QPushButton * dessiner;
QVBoxLayout * vbox;

};
#endif // FENPRINCIPALE_H




//FenCC.cpp

#include "FenDessin.h"
#include "FenPrincipale.h"
#include "FenCC.h"
FenCC::FenCC( QDialog *parent = 0) :QDialog(parent)
{
fermer = new QPushButton("Fermer",this);

connect(fermer, SIGNAL(clicked()), this, SLOT(accept()));

}



//FenDessin.cpp
#include "FenDessin.h"
#include "FenPrincipale.h"
#include "FenCC.h"
FenDessin::FenDessin( FenPrincipale *parent) :QDialog(parent),ref(parent)
{
Composante = new QPushButton("Composante",this);
QPaintEvent *c=NULL;
paintEvent(c);

connect(Composante, SIGNAL(clicked()), this, SLOT(CC()));

}

void FenDessin::paintEvent(QPaintEvent *c)
{
QPainter painter(this);


int tour=0;
int x=10;
int y=10;
int Num_Sommet=0;
int T_Coordonnees [10][3];
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
(T_Coordonnees[Num_Sommet][0])=x;
(T_Coordonnees[Num_Sommet][1])=y;
(T_Coordonnees[Num_Sommet][2])=tour;

if (tour==0)
{
x+=35;
tour=1;
}
else
{
y+=55;
tour=0;
}

}

int w1=0;
int w2=0;
int cpt=10;
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
if ( (T_Coordonnees[Num_Sommet][2])==1)
{ if(w1==0)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+500) ;
w1=1;
}
else
{
if(w1==1)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+250+cpt) ;
w1=0;
cpt=cpt+15;
}
}
if (Num_Sommet==9)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}

}
else
{
if(w2==0)
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+200;
w2=1;
}
else
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+100+cpt;
w2=0;
cpt=cpt+15;
}

if (Num_Sommet==4)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}
}
painter.drawEllipse((T_Coordonnees[Num_Sommet][0]), (T_Coordonnees[Num_Sommet][1]), 30.0, 30.0);
}

int i,j;
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j])==1)
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
}
}
}



for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j]==1) && (ref->M[j][i]==1))
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
if( (T_Coordonnees[i][1]>45)||(T_Coordonnees[j][1]>45) )
{
painter.drawLine(((T_Coordonnees[i][0]+20)-10),(T_Coordonnees[i][1]),((T_Coordonnees[j][0]+20)-10),(T_Coordonnees[j][1]));
}
else
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]+30),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]+30));
}
}
}
}
////////////////////////////////////////////////
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
QPoint point = QPoint( (((T_Coordonnees[Num_Sommet][0])+15)), ((T_Coordonnees[Num_Sommet][1])+15) );
QString str;
str.setNum(Num_Sommet);
painter.drawText( point,str);

}
}
void FenDessin::CC()
{

FenCC *fenetreCC = new FenCC(this);
fenetreCC->setFixedSize(900,900);
fenetreCC->show();
}



//FenPrincipale.cpp
#include "qDebug.h"
#include "FenDessin.h"
#include "FenPrincipale.h"
#include "FenCC.h"
FenPrincipale::FenPrincipale()
{
tabM =new QTableWidget(this);
tabM->setRowCount(10);
tabM->setColumnCount(10);
generer = new QPushButton("&Générer !",this);
dessiner = new QPushButton("&Dessiner !",this);

QVBoxLayout* vbox = new QVBoxLayout();
vbox->addWidget(generer);
vbox->addWidget(dessiner);
vbox->addWidget(tabM);
this->setLayout(vbox);
for (int r = 0; r < 10; r++) {
for (int c = 0; c < 10; 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 < 10; r++) {
for (int c = 0; c < 10; 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];
}
}
connect(dessiner, SIGNAL(clicked()), this, SLOT(FenetreDessin()));
}
void FenPrincipale::FenetreDessin()
{
FenDessin *fenetreC = new FenDessin(this);
fenetreC->setFixedSize(950,900);
fenetreC->show();
}



//main.cpp

#include <QApplication>
#include "FenDessin.h"
#include "FenPrincipale.h"
#include "FenCC.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
FenPrincipale fenetre;
fenetre.show();
return app.exec();
}


Can you please tell me what is wrong with it.

mentalmushroom
27th February 2012, 15:04
Don't include unnecessary headers, don't include header to itself. Use Q_OBJECT when needed.


//FenCC.h

#ifndef FENCC_H

#define FENCC_H

#include <QtGui>

//#include "FenDessin.h"

//#include "FenPrincipale.h"

//#include "FenCC.h"

class FenCC : public QDialog

{

public:

FenCC ( QDialog *parent);

private:

QPushButton *fermer;

private slots:

};

#endif





//FenDessin.h

#ifndef FENDESSIN_H

#define FENDESSIN_H

#include <QtGui>

//#include "FenDessin.h"

#include "FenPrincipale.h"

#include "FenCC.h"

class FenDessin : public QDialog

{
Q_OBJECT
public:

FenDessin ( FenPrincipale *parent);

private:

QPushButton *Composante;

QPainter *painter;

FenPrincipale *ref;

private slots:

void paintEvent (QPaintEvent *);

void CC ();

};

#endif // FENDESSIN_H




//FenPrinicipale.h

#ifndef FENPRINCIPALE_H

#define FENPRINCIPALE_H

#include <QtGui>

//#include "FenDessin.h"

//#include "FenPrincipale.h"

#include "FenCC.h"

class FenPrincipale : public QWidget

{

Q_OBJECT

public:

FenPrincipale();

bool M[10][10];



private slots:

void FillIn();

void FenetreDessin();

private:

QTableWidget *tabM;

QPushButton * generer;

QPushButton * dessiner;

QVBoxLayout * vbox;



};

#endif // FENPRINCIPALE_H




//FenCC.cpp



#include "FenDessin.h"

#include "FenPrincipale.h"

#include "FenCC.h"

FenCC::FenCC( QDialog *parent = 0) :QDialog(parent)

{

fermer = new QPushButton("Fermer",this);



connect(fermer, SIGNAL(clicked()), this, SLOT(accept()));



}




//FenDessin.cpp

#include "FenDessin.h"

#include "FenPrincipale.h"

#include "FenCC.h"

FenDessin::FenDessin( FenPrincipale *parent) :QDialog(parent),ref(parent)

{

Composante = new QPushButton("Composante",this);

QPaintEvent *c=NULL;

paintEvent(c);



connect(Composante, SIGNAL(clicked()), this, SLOT(CC()));



}

void FenDessin::paintEvent(QPaintEvent *c)

{

QPainter painter(this);





int tour=0;

int x=10;

int y=10;

int Num_Sommet=0;

int T_Coordonnees [10][3];

for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)

{

(T_Coordonnees[Num_Sommet][0])=x;

(T_Coordonnees[Num_Sommet][1])=y;

(T_Coordonnees[Num_Sommet][2])=tour;



if (tour==0)

{

x+=35;

tour=1;

}

else

{

y+=55;

tour=0;

}



}



int w1=0;

int w2=0;

int cpt=10;

Num_Sommet=0;

for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)

{

if ( (T_Coordonnees[Num_Sommet][2])==1)

{ if(w1==0)

{

(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+500) ;

w1=1;

}

else

{

if(w1==1)

{

(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+250+cpt) ;

w1=0;

cpt=cpt+15;

}

}

if (Num_Sommet==9)

{

(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;

}



}

else

{

if(w2==0)

{

(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+200;

w2=1;

}

else

{

(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+100+cpt;

w2=0;

cpt=cpt+15;

}



if (Num_Sommet==4)

{

(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;

}

}

painter.drawEllipse((T_Coordonnees[Num_Sommet][0]), (T_Coordonnees[Num_Sommet][1]), 30.0, 30.0);

}



int i,j;

for (i=0; i<10; i++)

{

for (j=0; j<10; j++)

{

if ((ref->M[i][j])==1)

{

painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));

}

}

}







for (i=0; i<10; i++)

{

for (j=0; j<10; j++)

{

if ((ref->M[i][j]==1) && (ref->M[j][i]==1))

{

painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));

if( (T_Coordonnees[i][1]>45)||(T_Coordonnees[j][1]>45) )

{

painter.drawLine(((T_Coordonnees[i][0]+20)-10),(T_Coordonnees[i][1]),((T_Coordonnees[j][0]+20)-10),(T_Coordonnees[j][1]));

}

else

{

painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]+30),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]+30));

}

}

}

}

////////////////////////////////////////////////

Num_Sommet=0;

for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)

{

QPoint point = QPoint( (((T_Coordonnees[Num_Sommet][0])+15)), ((T_Coordonnees[Num_Sommet][1])+15) );

QString str;

str.setNum(Num_Sommet);

painter.drawText( point,str);



}

}

void FenDessin::CC()

{



FenCC *fenetreCC = new FenCC(this);

fenetreCC->setFixedSize(900,900);

fenetreCC->show();

}




//FenPrincipale.cpp

#include "qDebug.h"

#include "FenDessin.h"

#include "FenPrincipale.h"

#include "FenCC.h"

FenPrincipale::FenPrincipale()

{

tabM =new QTableWidget(this);

tabM->setRowCount(10);

tabM->setColumnCount(10);

generer = new QPushButton("&Générer !",this);

dessiner = new QPushButton("&Dessiner !",this);



QVBoxLayout* vbox = new QVBoxLayout();

vbox->addWidget(generer);

vbox->addWidget(dessiner);

vbox->addWidget(tabM);

this->setLayout(vbox);

for (int r = 0; r < 10; r++) {

for (int c = 0; c < 10; 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 < 10; r++) {

for (int c = 0; c < 10; 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];

}

}

connect(dessiner, SIGNAL(clicked()), this, SLOT(FenetreDessin()));

}

void FenPrincipale::FenetreDessin()

{

FenDessin *fenetreC = new FenDessin(this);

fenetreC->setFixedSize(950,900);

fenetreC->show();

}






//main.cpp



#include <QApplication>

#include "FenDessin.h"

#include "FenPrincipale.h"

#include "FenCC.h"

int main(int argc, char* argv[])

{

QApplication app(argc, argv);

FenPrincipale fenetre;

fenetre.show();

return app.exec();

}

hichemnho
5th March 2012, 20:20
Hello,
Thanks a lot for your help.
I have done some modifications but the program crashes after clicking on the "dessiner" button.
Here is the code:


//Dessin.h
#ifndef DESSIN_H
#define DESSIN_H
#include <QtGui>
#include "FenPrincipale.h"
class Dessin : public QWidget
{
public:
Dessin ( FenPrincipale* parent);
private:
QPainter *painter;
FenPrincipale * ref;
protected:
void paintEvent(QPaintEvent *event);
};
#endif



//FenCC.h
#ifndef FENCC_H
#define FENCC_H
#include <QtGui>
class FenCC : public QDialog
{
public:
FenCC(QWidget *parent = 0);
private:
QPushButton *fermer;
private slots:
};
#endif



//FenDessin.h
#ifndef FENDESSIN_H
//FenDessin.h
#define FENDESSIN_H
#include "FenPrincipale.h"
#include "FenCC.h"
#include "Dessin.h"
class FenDessin : public QWidget
{

public:
FenDessin ( FenPrincipale* parent);
private:
QPushButton *Composante;
FenPrincipale *ref;
Dessin *dessin;
FenPrincipale *fenetre1;
FenCC *fenetre3;
private slots:
void CC ();
};
#endif // FENDESSIN_H


//FenPrinicipale.h
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
class FenPrincipale : public QWidget
{
Q_OBJECT
public:
FenPrincipale();
bool M[10][10];

private slots:
void FillIn();
void FenetreDessin();
private:
QTableWidget *tabM;
QPushButton * generer;
QPushButton * dessiner;
QVBoxLayout * vbox;

};
#endif // FENPRINCIPALE_H



//Dessin.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
Dessin::Dessin( FenPrincipale *parent) :QWidget(parent),ref(parent)//doit avoir fenprincipale comme parent
{
setFixedSize(900,900);
QPaintEvent *c=NULL;
paintEvent(c);
}

void Dessin::paintEvent(QPaintEvent *event)
{
QPainter painter(this);


int tour=0;
int x=10;
int y=10;
int Num_Sommet=0;
int T_Coordonnees [10][3];
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
(T_Coordonnees[Num_Sommet][0])=x;
(T_Coordonnees[Num_Sommet][1])=y;
(T_Coordonnees[Num_Sommet][2])=tour;

if (tour==0)
{
x+=35;
tour=1;
}
else
{
y+=55;
tour=0;
}

}

int w1=0;
int w2=0;
int cpt=10;
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
if ( (T_Coordonnees[Num_Sommet][2])==1)
{ if(w1==0)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+500) ;
w1=1;
}
else
{
if(w1==1)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+250+cpt) ;
w1=0;
cpt=cpt+15;
}
}
if (Num_Sommet==9)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}

}
else
{
if(w2==0)
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+200;
w2=1;
}
else
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+100+cpt;
w2=0;
cpt=cpt+15;
}

if (Num_Sommet==4)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}
}
painter.drawEllipse((T_Coordonnees[Num_Sommet][0]), (T_Coordonnees[Num_Sommet][1]), 30.0, 30.0);
}

int i,j;
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j])==1)
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
}
}
}



for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j]==1) && (ref->M[j][i]==1))
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
if( (T_Coordonnees[i][1]>45)||(T_Coordonnees[j][1]>45) )
{
painter.drawLine(((T_Coordonnees[i][0]+20)-10),(T_Coordonnees[i][1]),((T_Coordonnees[j][0]+20)-10),(T_Coordonnees[j][1]));
}
else
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]+30),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]+30));
}
}
}
}
////////////////////////////////////////////////
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
QPoint point = QPoint( (((T_Coordonnees[Num_Sommet][0])+15)), ((T_Coordonnees[Num_Sommet][1])+15) );
QString str;
str.setNum(Num_Sommet);
painter.drawText( point,str);

}
}



//FenCC.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
FenCC::FenCC(QWidget *parent) : QDialog(parent)
{
fermer = new QPushButton("Fermer",this);
connect(fermer, SIGNAL(clicked()), this, SLOT(accept()));

}


//FenDessin.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"

FenDessin::FenDessin( FenPrincipale *parent) :QWidget(parent),ref(parent)
{
Composante = new QPushButton("Composante",this);
dessin = new Dessin((fenetre1));
QVBoxLayout *vBoxLayout = new QVBoxLayout;
vBoxLayout->addWidget(dessin);
vBoxLayout->addWidget(Composante);
setLayout(vBoxLayout);
connect(Composante, SIGNAL(clicked()), this, SLOT(CC()));

}
void FenDessin::CC()
{
fenetre3 = new FenCC (this);
fenetre3->show();
}




//FenPrincipale.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
FenPrincipale::FenPrincipale()
{
tabM =new QTableWidget(this);
tabM->setRowCount(10);
tabM->setColumnCount(10);
generer = new QPushButton("&Générer !",this);
dessiner = new QPushButton("&Dessiner !",this);

QVBoxLayout* vbox = new QVBoxLayout();
vbox->addWidget(generer);
vbox->addWidget(dessiner);
vbox->addWidget(tabM);
this->setLayout(vbox);
for (int r = 0; r < 10; r++) {
for (int c = 0; c < 10; 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 < 10; r++) {
for (int c = 0; c < 10; 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];
}
}
connect(dessiner, SIGNAL(clicked()), this, SLOT(FenetreDessin()));
}
void FenPrincipale::FenetreDessin()
{
FenDessin *fenetre2 = new FenDessin(this);
fenetre2->setFixedSize(950,900);
fenetre2->show();
}


//main.cpp
#include <QApplication>
#include "FenPrincipale.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
FenPrincipale fenetre1;
fenetre1.show();
return app.exec();
}






Please help me with this .
Thank you in advance for the attention and time given to this message.

ChrisW67
5th March 2012, 21:48
Run a debug version of your program in a debugger. When it crashes look at the stack trace that is produced, read from top down until you reach an entry that is your code. This will tell you exactly which line of your code caused the crash. Armed with this information you can look at the variable values in force at the time Click on that entry in the stack trace). My money is on a NULL or invalid pointer.