Results 1 to 6 of 6

Thread: create a QDialog from a QDialog

  1. #1
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default create a QDialog from a QDialog

    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.

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: create a QDialog from a QDialog

    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"

  3. #3
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: create a QDialog from a QDialog

    Thank you very much for your answer,


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

  4. #4
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: create a QDialog from a QDialog

    Don't include unnecessary headers, don't include header to itself. Use Q_OBJECT when needed.
    Qt Code:
    1. //FenCC.h
    2.  
    3. #ifndef FENCC_H
    4.  
    5. #define FENCC_H
    6.  
    7. #include <QtGui>
    8.  
    9. //#include "FenDessin.h"
    10.  
    11. //#include "FenPrincipale.h"
    12.  
    13. //#include "FenCC.h"
    14.  
    15. class FenCC : public QDialog
    16.  
    17. {
    18.  
    19. public:
    20.  
    21. FenCC ( QDialog *parent);
    22.  
    23. private:
    24.  
    25. QPushButton *fermer;
    26.  
    27. private slots:
    28.  
    29. };
    30.  
    31. #endif
    32.  
    33.  
    34.  
    35.  
    36.  
    37. //FenDessin.h
    38.  
    39. #ifndef FENDESSIN_H
    40.  
    41. #define FENDESSIN_H
    42.  
    43. #include <QtGui>
    44.  
    45. //#include "FenDessin.h"
    46.  
    47. #include "FenPrincipale.h"
    48.  
    49. #include "FenCC.h"
    50.  
    51. class FenDessin : public QDialog
    52.  
    53. {
    54. Q_OBJECT
    55. public:
    56.  
    57. FenDessin ( FenPrincipale *parent);
    58.  
    59. private:
    60.  
    61. QPushButton *Composante;
    62.  
    63. QPainter *painter;
    64.  
    65. FenPrincipale *ref;
    66.  
    67. private slots:
    68.  
    69. void paintEvent (QPaintEvent *);
    70.  
    71. void CC ();
    72.  
    73. };
    74.  
    75. #endif // FENDESSIN_H
    76.  
    77.  
    78.  
    79.  
    80. //FenPrinicipale.h
    81.  
    82. #ifndef FENPRINCIPALE_H
    83.  
    84. #define FENPRINCIPALE_H
    85.  
    86. #include <QtGui>
    87.  
    88. //#include "FenDessin.h"
    89.  
    90. //#include "FenPrincipale.h"
    91.  
    92. #include "FenCC.h"
    93.  
    94. class FenPrincipale : public QWidget
    95.  
    96. {
    97.  
    98. Q_OBJECT
    99.  
    100. public:
    101.  
    102. FenPrincipale();
    103.  
    104. bool M[10][10];
    105.  
    106.  
    107.  
    108. private slots:
    109.  
    110. void FillIn();
    111.  
    112. void FenetreDessin();
    113.  
    114. private:
    115.  
    116. QTableWidget *tabM;
    117.  
    118. QPushButton * generer;
    119.  
    120. QPushButton * dessiner;
    121.  
    122. QVBoxLayout * vbox;
    123.  
    124.  
    125.  
    126. };
    127.  
    128. #endif // FENPRINCIPALE_H
    129.  
    130.  
    131.  
    132.  
    133. //FenCC.cpp
    134.  
    135.  
    136.  
    137. #include "FenDessin.h"
    138.  
    139. #include "FenPrincipale.h"
    140.  
    141. #include "FenCC.h"
    142.  
    143. FenCC::FenCC( QDialog *parent = 0) :QDialog(parent)
    144.  
    145. {
    146.  
    147. fermer = new QPushButton("Fermer",this);
    148.  
    149.  
    150.  
    151. connect(fermer, SIGNAL(clicked()), this, SLOT(accept()));
    152.  
    153.  
    154.  
    155. }
    156.  
    157.  
    158.  
    159.  
    160. //FenDessin.cpp
    161.  
    162. #include "FenDessin.h"
    163.  
    164. #include "FenPrincipale.h"
    165.  
    166. #include "FenCC.h"
    167.  
    168. FenDessin::FenDessin( FenPrincipale *parent) :QDialog(parent),ref(parent)
    169.  
    170. {
    171.  
    172. Composante = new QPushButton("Composante",this);
    173.  
    174. QPaintEvent *c=NULL;
    175.  
    176. paintEvent(c);
    177.  
    178.  
    179.  
    180. connect(Composante, SIGNAL(clicked()), this, SLOT(CC()));
    181.  
    182.  
    183.  
    184. }
    185.  
    186. void FenDessin::paintEvent(QPaintEvent *c)
    187.  
    188. {
    189.  
    190. QPainter painter(this);
    191.  
    192.  
    193.  
    194.  
    195.  
    196. int tour=0;
    197.  
    198. int x=10;
    199.  
    200. int y=10;
    201.  
    202. int Num_Sommet=0;
    203.  
    204. int T_Coordonnees [10][3];
    205.  
    206. for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
    207.  
    208. {
    209.  
    210. (T_Coordonnees[Num_Sommet][0])=x;
    211.  
    212. (T_Coordonnees[Num_Sommet][1])=y;
    213.  
    214. (T_Coordonnees[Num_Sommet][2])=tour;
    215.  
    216.  
    217.  
    218. if (tour==0)
    219.  
    220. {
    221.  
    222. x+=35;
    223.  
    224. tour=1;
    225.  
    226. }
    227.  
    228. else
    229.  
    230. {
    231.  
    232. y+=55;
    233.  
    234. tour=0;
    235.  
    236. }
    237.  
    238.  
    239.  
    240. }
    241.  
    242.  
    243.  
    244. int w1=0;
    245.  
    246. int w2=0;
    247.  
    248. int cpt=10;
    249.  
    250. Num_Sommet=0;
    251.  
    252. for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
    253.  
    254. {
    255.  
    256. if ( (T_Coordonnees[Num_Sommet][2])==1)
    257.  
    258. { if(w1==0)
    259.  
    260. {
    261.  
    262. (T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+500) ;
    263.  
    264. w1=1;
    265.  
    266. }
    267.  
    268. else
    269.  
    270. {
    271.  
    272. if(w1==1)
    273.  
    274. {
    275.  
    276. (T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+250+cpt) ;
    277.  
    278. w1=0;
    279.  
    280. cpt=cpt+15;
    281.  
    282. }
    283.  
    284. }
    285.  
    286. if (Num_Sommet==9)
    287.  
    288. {
    289.  
    290. (T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
    291.  
    292. }
    293.  
    294.  
    295.  
    296. }
    297.  
    298. else
    299.  
    300. {
    301.  
    302. if(w2==0)
    303.  
    304. {
    305.  
    306. (T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+200;
    307.  
    308. w2=1;
    309.  
    310. }
    311.  
    312. else
    313.  
    314. {
    315.  
    316. (T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+100+cpt;
    317.  
    318. w2=0;
    319.  
    320. cpt=cpt+15;
    321.  
    322. }
    323.  
    324.  
    325.  
    326. if (Num_Sommet==4)
    327.  
    328. {
    329.  
    330. (T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
    331.  
    332. }
    333.  
    334. }
    335.  
    336. painter.drawEllipse((T_Coordonnees[Num_Sommet][0]), (T_Coordonnees[Num_Sommet][1]), 30.0, 30.0);
    337.  
    338. }
    339.  
    340.  
    341.  
    342. int i,j;
    343.  
    344. for (i=0; i<10; i++)
    345.  
    346. {
    347.  
    348. for (j=0; j<10; j++)
    349.  
    350. {
    351.  
    352. if ((ref->M[i][j])==1)
    353.  
    354. {
    355.  
    356. painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
    357.  
    358. }
    359.  
    360. }
    361.  
    362. }
    363.  
    364.  
    365.  
    366.  
    367.  
    368.  
    369.  
    370. for (i=0; i<10; i++)
    371.  
    372. {
    373.  
    374. for (j=0; j<10; j++)
    375.  
    376. {
    377.  
    378. if ((ref->M[i][j]==1) && (ref->M[j][i]==1))
    379.  
    380. {
    381.  
    382. painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
    383.  
    384. if( (T_Coordonnees[i][1]>45)||(T_Coordonnees[j][1]>45) )
    385.  
    386. {
    387.  
    388. painter.drawLine(((T_Coordonnees[i][0]+20)-10),(T_Coordonnees[i][1]),((T_Coordonnees[j][0]+20)-10),(T_Coordonnees[j][1]));
    389.  
    390. }
    391.  
    392. else
    393.  
    394. {
    395.  
    396. painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]+30),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]+30));
    397.  
    398. }
    399.  
    400. }
    401.  
    402. }
    403.  
    404. }
    405.  
    406. ////////////////////////////////////////////////
    407.  
    408. Num_Sommet=0;
    409.  
    410. for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
    411.  
    412. {
    413.  
    414. QPoint point = QPoint( (((T_Coordonnees[Num_Sommet][0])+15)), ((T_Coordonnees[Num_Sommet][1])+15) );
    415.  
    416. QString str;
    417.  
    418. str.setNum(Num_Sommet);
    419.  
    420. painter.drawText( point,str);
    421.  
    422.  
    423.  
    424. }
    425.  
    426. }
    427.  
    428. void FenDessin::CC()
    429.  
    430. {
    431.  
    432.  
    433.  
    434. FenCC *fenetreCC = new FenCC(this);
    435.  
    436. fenetreCC->setFixedSize(900,900);
    437.  
    438. fenetreCC->show();
    439.  
    440. }
    441.  
    442.  
    443.  
    444.  
    445. //FenPrincipale.cpp
    446.  
    447. #include "qDebug.h"
    448.  
    449. #include "FenDessin.h"
    450.  
    451. #include "FenPrincipale.h"
    452.  
    453. #include "FenCC.h"
    454.  
    455. FenPrincipale::FenPrincipale()
    456.  
    457. {
    458.  
    459. tabM =new QTableWidget(this);
    460.  
    461. tabM->setRowCount(10);
    462.  
    463. tabM->setColumnCount(10);
    464.  
    465. generer = new QPushButton("&Générer !",this);
    466.  
    467. dessiner = new QPushButton("&Dessiner !",this);
    468.  
    469.  
    470.  
    471. QVBoxLayout* vbox = new QVBoxLayout();
    472.  
    473. vbox->addWidget(generer);
    474.  
    475. vbox->addWidget(dessiner);
    476.  
    477. vbox->addWidget(tabM);
    478.  
    479. this->setLayout(vbox);
    480.  
    481. for (int r = 0; r < 10; r++) {
    482.  
    483. for (int c = 0; c < 10; c++) {
    484.  
    485.  
    486. tabM->setItem(r, c, it);
    487.  
    488. it->setData(Qt::EditRole, 0);
    489.  
    490.  
    491.  
    492. }
    493.  
    494. }
    495.  
    496. connect(generer, SIGNAL(clicked()), this, SLOT(FillIn()));
    497.  
    498. }
    499.  
    500. void FenPrincipale::FillIn()
    501.  
    502. {
    503.  
    504. for (int r = 0; r < 10; r++) {
    505.  
    506. for (int c = 0; c < 10; c++) {
    507.  
    508. QTableWidgetItem *it = tabM->item(r,c);;
    509.  
    510. Q_ASSERT(it);
    511.  
    512. qDebug() <<it;
    513.  
    514. int val = (it->data(Qt::EditRole)).toInt();
    515.  
    516. M[r][c] = (val == 1)? true: false;
    517.  
    518. // qDebug() <<M[r][c];
    519.  
    520. }
    521.  
    522. }
    523.  
    524. connect(dessiner, SIGNAL(clicked()), this, SLOT(FenetreDessin()));
    525.  
    526. }
    527.  
    528. void FenPrincipale::FenetreDessin()
    529.  
    530. {
    531.  
    532. FenDessin *fenetreC = new FenDessin(this);
    533.  
    534. fenetreC->setFixedSize(950,900);
    535.  
    536. fenetreC->show();
    537.  
    538. }
    539.  
    540.  
    541.  
    542.  
    543.  
    544.  
    545. //main.cpp
    546.  
    547.  
    548.  
    549. #include <QApplication>
    550.  
    551. #include "FenDessin.h"
    552.  
    553. #include "FenPrincipale.h"
    554.  
    555. #include "FenCC.h"
    556.  
    557. int main(int argc, char* argv[])
    558.  
    559. {
    560.  
    561. QApplication app(argc, argv);
    562.  
    563. FenPrincipale fenetre;
    564.  
    565. fenetre.show();
    566.  
    567. return app.exec();
    568.  
    569. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: create a QDialog from a QDialog

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

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: create a QDialog from a QDialog

    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.

Similar Threads

  1. Replies: 9
    Last Post: 25th March 2011, 21:22
  2. QDialog.exec() exiting without calling QDialog::accept()
    By doggrant in forum Qt Programming
    Replies: 3
    Last Post: 2nd February 2011, 11:35
  3. Replies: 4
    Last Post: 25th December 2010, 16:20
  4. closing a Qdialog called from a Qdialog
    By OverTheOCean in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2009, 08:02
  5. How to "lock" a new qdialog in another qdialog
    By donglebob in forum Qt Programming
    Replies: 7
    Last Post: 4th February 2009, 08:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.