Results 1 to 6 of 6

Thread: Dialog is not closing

  1. #1
    Join Date
    Nov 2008
    Posts
    39
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Dialog is not closing

    Hi dudes,

    I am a newbie to qt and I have a small problem...

    I created 2 dialogs with 2 push buttons, and 2 labels to indicate the dialogs, I have generated a simple code using which I am able to open the first dialog screen and when I click on the first dialog's push button the second screen is poping up but I am unable to close the first dialog completely.......

    The basic need is click on the first dialogs push button it should pop up the second dialog and close the first dialog completely, when I click on the second dialogs push button it should close the second dialog completely and the push up the first dialog..... vice versa... so...

    Seems to be a crazy idea but can we do it...

    I have checked out the FAQ's to open a new dialog... I have use the simple code....

    copied code from FAQ's
    Qt Code:
    1. void someClass::someMethod()
    2. {
    3. firstDialog::close();
    4. secondDialog *dialog = new secondDialog(this);
    5. dialog->show();
    6. }
    To copy to clipboard, switch view to plain text mode 


    This was the simple code Which I have used... if I use the code I am able to reach near to the assumption but when I try to close the dialog using the upper "X" mark then I abserved that there were to many windows to close... this shows that the windows which I have opened using the new Dialog(this) are not closing ...

    Is there any way to close the dialogs....

    Thanks for the help
    Last edited by jpn; 2nd December 2008 at 18:44. Reason: missing [code] tags

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Dialog is not closing

    could be better if you provide more code.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    manmohan (28th November 2008)

  4. #3
    Join Date
    Nov 2008
    Posts
    39
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb Re: Dialog is not closing

    Thank's for looking at my problem by the way this is the complete code

    Qt Code:
    1. main.cpp
    2. ==========
    3.  
    4. #include <QtGui/QApplication>
    5. #include "dialog.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10. Dialog w;
    11. w.show();
    12. return a.exec();
    13. }
    14.  
    15. ########################################
    16.  
    17. dialog.cpp
    18. ============
    19.  
    20. #include <QtGui>
    21. #include "dialog.h"
    22. #include "x1dialog.h"
    23.  
    24. Dialog::Dialog(QWidget *parent)
    25. : QDialog(parent)
    26. {
    27. setupUi(this);
    28. connect(pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));
    29. }
    30.  
    31. void Dialog::on_pushButton_clicked()
    32. {
    33. Dialog::close();
    34. x1Dialog dialog(this);
    35. dialog.exec();
    36.  
    37. }
    38.  
    39. dialog.h
    40. ===========
    41. #ifndef DIALOG_H
    42. #define DIALOG_H
    43.  
    44. #include <QtGui/QDialog>
    45. #include "ui_dialog.h"
    46.  
    47. class Dialog : public QDialog, public Ui::Dialog
    48. {
    49. Q_OBJECT
    50.  
    51. public:
    52. Dialog(QWidget *parent = 0);
    53.  
    54. public slots:
    55. void on_pushButton_clicked();
    56. };
    57.  
    58. #endif
    59.  
    60. dialog.ui
    61. ============
    62. <ui version="4.0" >
    63. <class>Dialog</class>
    64. <widget class="QDialog" name="Dialog" >
    65. <property name="geometry" >
    66. <rect>
    67. <x>0</x>
    68. <y>0</y>
    69. <width>400</width>
    70. <height>300</height>
    71. </rect>
    72. </property>
    73. <property name="windowTitle" >
    74. <string>Dialog</string>
    75. </property>
    76. <widget class="QPushButton" name="pushButton" >
    77. <property name="geometry" >
    78. <rect>
    79. <x>60</x>
    80. <y>100</y>
    81. <width>75</width>
    82. <height>28</height>
    83. </rect>
    84. </property>
    85. <property name="text" >
    86. <string>PushButton</string>
    87. </property>
    88. </widget>
    89. <widget class="QLabel" name="label" >
    90. <property name="geometry" >
    91. <rect>
    92. <x>170</x>
    93. <y>70</y>
    94. <width>161</width>
    95. <height>131</height>
    96. </rect>
    97. </property>
    98. <property name="text" >
    99. <string>This is the 1st dialog</string>
    100. </property>
    101. </widget>
    102. </widget>
    103. <resources/>
    104. <connections/>
    105. </ui>
    106.  
    107. ###############################################################################
    108.  
    109. x1dialog.cpp
    110. ===============
    111. #include <QtGui>
    112. #include "dialog.h"
    113. #include "x1dialog.h"
    114.  
    115. x1Dialog::x1Dialog(QWidget *parent)
    116. : QDialog(parent)
    117. {
    118. setupUi(this);
    119. connect(pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));
    120. }
    121.  
    122. void x1Dialog::on_pushButton_clicked()
    123. {
    124. x1Dialog::close();
    125. Dialog dialog(this);
    126. dialog.exec();
    127.  
    128. }
    129.  
    130. x1dialog.h
    131. =============
    132. #ifndef X1DIALOG_H
    133. #define X1DIALOG_H
    134.  
    135. #include <QtGui/QDialog>
    136. #include "ui_x1dialog.h"
    137.  
    138. class x1Dialog : public QDialog, public Ui::x1Dialog
    139. {
    140. Q_OBJECT
    141.  
    142. public:
    143. x1Dialog(QWidget *parent = 0);
    144.  
    145. public slots:
    146. void on_pushButton_clicked();
    147. };
    148.  
    149. #endif
    150.  
    151. x1dialog.ui
    152. ==============
    153. <ui version="4.0" >
    154. <class>x1Dialog</class>
    155. <widget class="QDialog" name="x1Dialog" >
    156. <property name="geometry" >
    157. <rect>
    158. <x>0</x>
    159. <y>0</y>
    160. <width>400</width>
    161. <height>300</height>
    162. </rect>
    163. </property>
    164. <property name="windowTitle" >
    165. <string>x1Dialog</string>
    166. </property>
    167. <widget class="QPushButton" name="pushButton" >
    168. <property name="geometry" >
    169. <rect>
    170. <x>60</x>
    171. <y>100</y>
    172. <width>75</width>
    173. <height>28</height>
    174. </rect>
    175. </property>
    176. <property name="text" >
    177. <string>PushButton</string>
    178. </property>
    179. </widget>
    180. <widget class="QLabel" name="label" >
    181. <property name="geometry" >
    182. <rect>
    183. <x>170</x>
    184. <y>70</y>
    185. <width>161</width>
    186. <height>131</height>
    187. </rect>
    188. </property>
    189. <property name="text" >
    190. <string>This is the 2nd dialog</string>
    191. </property>
    192. </widget>
    193. </widget>
    194. <resources/>
    195. <connections/>
    196. </ui>
    To copy to clipboard, switch view to plain text mode 

    How ever I am attaching a copy of the conntent..........................



    compiled on linux ubuntu
    Last edited by marcel; 29th November 2008 at 17:57. Reason: missing [code] tags

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Dialog is not closing

    so, the problem is: on_pushButton_clicked() is called twice, because if you use such kind of slot naming on_pushButton_clicked then you don't need to connect it manually, because it will be made automatically. so, in your case two connections were created.
    so, you need to comment these connections
    Qt Code:
    1. connect(pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));
    2. connect(pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));
    To copy to clipboard, switch view to plain text mode 
    or rename slots.
    see this for more details QMetaObject::connectSlotsByName.
    PS. please, use tags CODE.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #5
    Join Date
    Nov 2008
    Posts
    39
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dialog is not closing

    Thank you very much, I have found this very much help full now the program works well...

  7. #6
    Join Date
    Nov 2008
    Posts
    39
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: Dialog is not closing

    May I know a best guide to learn the opengl ???????

Similar Threads

  1. Replies: 9
    Last Post: 13th August 2008, 18:07
  2. Resizing the dialog boxes
    By anju123 in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2007, 10:41
  3. QGraphicsView: Dialog Position Doubt
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2007, 17:48
  4. closing dialog in hidden main Widget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2006, 10:35
  5. Replies: 3
    Last Post: 23rd July 2006, 18:02

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.