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:

Qt Code:
  1. //FenPrincipale.h
  2. //FenPrinicipale.h
  3. #ifndef FENPRINCIPALE_H
  4. #define FENPRINCIPALE_H
  5. #include <QtGui>
  6.  
  7. class FenPrincipale : public QWidget
  8. {
  9. Q_OBJECT
  10. public:
  11. FenPrincipale();
  12. bool M[10][10];
  13.  
  14. private slots:
  15. void FillIn();
  16. void FenetreDessin();
  17. private:
  18. QTableWidget *tabM;
  19. QPushButton * generer;
  20. QPushButton * dessiner;
  21. QVBoxLayout * vbox;
  22.  
  23. };
  24. #endif // FENPRINCIPALE_H
  25.  
  26. //FenPrincipale.cpp
  27.  
  28. //FenPrincipale.cpp
  29. #include "qDebug.h"
  30. #include "FenPrincipale.h"
  31. #include "FenDessin.h"
  32. FenPrincipale::FenPrincipale()
  33. {
  34. tabM =new QTableWidget(this);
  35. tabM->setRowCount(10);
  36. tabM->setColumnCount(10);
  37. generer = new QPushButton("&Générer !",this);
  38. dessiner = new QPushButton("&Dessiner !",this);
  39.  
  40. QVBoxLayout* vbox = new QVBoxLayout();
  41. vbox->addWidget(generer);
  42. vbox->addWidget(dessiner);
  43. vbox->addWidget(tabM);
  44. this->setLayout(vbox);
  45. for (int r = 0; r < 10; r++) {
  46. for (int c = 0; c < 10; c++) {
  47. tabM->setItem(r, c, it);
  48. it->setData(Qt::EditRole, 0);
  49.  
  50. }
  51. }
  52. connect(generer, SIGNAL(clicked()), this, SLOT(FillIn()));
  53. }
  54. void FenPrincipale::FillIn()
  55. {
  56. for (int r = 0; r < 10; r++) {
  57. for (int c = 0; c < 10; c++) {
  58. QTableWidgetItem *it = tabM->item(r,c);;
  59. Q_ASSERT(it);
  60. qDebug() <<it;
  61. int val = (it->data(Qt::EditRole)).toInt();
  62. M[r][c] = (val == 1)? true: false;
  63. // qDebug() <<M[r][c];
  64. }
  65. }
  66. connect(dessiner, SIGNAL(clicked()), this, SLOT(FenetreDessin()));
  67. }
  68. void FenPrincipale::FenetreDessin()
  69. {
  70. FenDessin *fenetreC = new FenDessin(this);
  71. fenetreC->setFixedSize(950,900);
  72. fenetreC->show();
  73. }
  74.  
  75.  
  76. //FenDessin.h
  77. //FenDessin.h
  78. #ifndef FENDESSIN_H
  79. #define FENDESSIN_H
  80. #include <QtGui>
  81. #include"FenPrincipale.h"
  82. class FenDessin : public QWidget
  83. {
  84. public:
  85. FenDessin ( FenPrincipale* parent);
  86. private:
  87. QPushButton *Composante;
  88. QPainter *painter;
  89. FenPrincipale * ref;
  90. private slots:
  91. void paintEvent (QPaintEvent *);
  92. void CC ();
  93. };
  94. #endif // FENDESSIN_H
  95.  
  96. //FenDessin.cpp
  97. #include "FenDessin.h"
  98. #include "FenPrincipale.h"
  99. #include "FenCC.h"
  100. FenDessin::FenDessin( FenPrincipale *parent) :QDialog(parent),ref(parent)
  101. {
  102. Composante = new QPushButton("Composante",this);
  103. QPaintEvent *c=NULL;
  104. paintEvent(c);
  105.  
  106. connect(Composante, SIGNAL(clicked()), this, SLOT(CC()));
  107.  
  108. }
  109.  
  110. void FenDessin::paintEvent(QPaintEvent *c)
  111. {
  112. QPainter painter(this);
  113.  
  114.  
  115. int tour=0;
  116. int x=10;
  117. int y=10;
  118. int Num_Sommet=0;
  119. int T_Coordonnees [10][3];
  120. for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
  121. {
  122. (T_Coordonnees[Num_Sommet][0])=x;
  123. (T_Coordonnees[Num_Sommet][1])=y;
  124. (T_Coordonnees[Num_Sommet][2])=tour;
  125.  
  126. if (tour==0)
  127. {
  128. x+=35;
  129. tour=1;
  130. }
  131. else
  132. {
  133. y+=55;
  134. tour=0;
  135. }
  136.  
  137. }
  138.  
  139. int w1=0;
  140. int w2=0;
  141. int cpt=10;
  142. Num_Sommet=0;
  143. for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
  144. {
  145. if ( (T_Coordonnees[Num_Sommet][2])==1)
  146. { if(w1==0)
  147. {
  148. (T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+500) ;
  149. w1=1;
  150. }
  151. else
  152. {
  153. if(w1==1)
  154. {
  155. (T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+250+cpt) ;
  156. w1=0;
  157. cpt=cpt+15;
  158. }
  159. }
  160. if (Num_Sommet==9)
  161. {
  162. (T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
  163. }
  164.  
  165. }
  166. else
  167. {
  168. if(w2==0)
  169. {
  170. (T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+200;
  171. w2=1;
  172. }
  173. else
  174. {
  175. (T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+100+cpt;
  176. w2=0;
  177. cpt=cpt+15;
  178. }
  179.  
  180. if (Num_Sommet==4)
  181. {
  182. (T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
  183. }
  184. }
  185. painter.drawEllipse((T_Coordonnees[Num_Sommet][0]), (T_Coordonnees[Num_Sommet][1]), 30.0, 30.0);
  186. }
  187.  
  188. int i,j;
  189. for (i=0; i<10; i++)
  190. {
  191. for (j=0; j<10; j++)
  192. {
  193. if ((ref->M[i][j])==1)
  194. {
  195. painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
  196. }
  197. }
  198. }
  199.  
  200.  
  201.  
  202. for (i=0; i<10; i++)
  203. {
  204. for (j=0; j<10; j++)
  205. {
  206. if ((ref->M[i][j]==1) && (ref->M[j][i]==1))
  207. {
  208. painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
  209. if( (T_Coordonnees[i][1]>45)||(T_Coordonnees[j][1]>45) )
  210. {
  211. painter.drawLine(((T_Coordonnees[i][0]+20)-10),(T_Coordonnees[i][1]),((T_Coordonnees[j][0]+20)-10),(T_Coordonnees[j][1]));
  212. }
  213. else
  214. {
  215. painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]+30),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]+30));
  216. }
  217. }
  218. }
  219. }
  220. ////////////////////////////////////////////////
  221. Num_Sommet=0;
  222. for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
  223. {
  224. QPoint point = QPoint( (((T_Coordonnees[Num_Sommet][0])+15)), ((T_Coordonnees[Num_Sommet][1])+15) );
  225. QString str;
  226. str.setNum(Num_Sommet);
  227. painter.drawText( point,str);
  228.  
  229. }
  230. }
  231. void FenDessin::CC()
  232. {
  233.  
  234. FenCC *fenetreCC = new FenCC(this);
  235. fenetreCC->setFixedSize(900,900);
  236. fenetreCC->show();
  237. }
  238. //FenCC.h
  239. #ifndef FENCC_H
  240. #define FENCC_H
  241. #include <QtGui>
  242. class FenCC : public QDialog
  243. {
  244. public:
  245. FenCC ( QDialog *parent);
  246. private:
  247. QPushButton *fermer;
  248. private slots:
  249. };
  250. #endif
  251.  
  252. //FenCC.cpp
  253.  
  254. #include "FenCC.h"
  255. FenCC::FenCC( QDialog *parent = 0) :QDialog(parent)
  256. {
  257. fermer = new QPushButton("Fermer",this);
  258.  
  259. connect(fermer, SIGNAL(clicked()), this, SLOT(accept()));
  260.  
  261. }
  262.  
  263.  
  264. //main.cpp
  265.  
  266. #include <QApplication>
  267. #include "FenPrincipale.h"
  268. int main(int argc, char* argv[])
  269. {
  270. QApplication app(argc, argv);
  271. FenPrincipale fenetre;
  272. fenetre.show();
  273. return app.exec();
  274. }
To copy to clipboard, switch view to plain text mode 
Thank you in advance for your attention and help.