Hi

In the below code when i tries to close the dialog ,through the button I used in Window class then application crashes, but if I close it through the close button that is on the upper left corner that is "X" then it wont crashes and works fine and also no memory leakage. For this I use QDialog.exec() , So that modality should also set and "X" should also be visible but, using this QDialog.exec() also "X" Should not be visible.

Qt Code:
  1. [B][U]SelectFile.cpp[/U][/B]
  2.  
  3. void SelectFile::init()
  4. {
  5. connect(btn_SelectFile,SIGNAL(clicked()),this,SLOT(chooseMovie()));
  6. }
  7.  
  8. void SelectFile::chooseMovie()
  9. {
  10. QString TmpStr = QFileDialog::getOpenFileName(this);
  11. EnterMovies();
  12. if(movieWindow==NULL)
  13. Window *movieWindow = new Window(0);
  14. connect(this,SIGNAL(movieChosen(QString)),movieWindow,SLOT(OpenMovie(QString)));
  15. emit movieChosen(TmpStr);
  16. movieWindow->exec();
  17. ExitMovies();
  18. }
  19.  
  20.  
  21. [B][U]window.cpp[/U][/B]
  22.  
  23.  
  24. Window::Window(QWidget *parent)
  25. : QDialog(parent)
  26. {
  27. setupUi(this);
  28. movieWidget = new MovieWidget(this);
  29. connect(this, SIGNAL(movieChoose(QString)),movieWidget,SLOT(loadMovie (QString)));
  30. connect(movieWidget, SIGNAL(optimalSizeChange()),this, SLOT(updateSizes()));
  31. connect(movieWidget, SIGNAL(NoPreview()),this, SIGNAL(NoPreviewAvailable()));
  32. connect(btn_close, SIGNAL(clicked()), this, SLOT(Close()));
  33. layout()->addWidget(movieWidget);
  34. }
  35.  
  36. Window::~Window()
  37. {
  38.  
  39. }
  40.  
  41. void Window::Close()
  42. {
  43. connect(this, SIGNAL(DisposeCurrentMovie()),movieWidget,SLOT(dispose()));
  44. close();
  45. }
  46. void Window :: OpenMovie(QString bMovieName)
  47. {
  48. emit movieChoose(bMovieName);
  49. }
  50. void Window::updateSizes()
  51. {
  52. adjustSize();
  53. }
  54.  
  55.  
  56. [B][U]moviewidget.cpp
  57. [/U][/B]
  58. #include "moviewidget.h"
  59. #include <QtGui/QLayout>
  60. #include <Carbon/Carbon.h>
  61. #include <QuickTime/QuickTime.h>
  62.  
  63. MovieWidget::MovieWidget(QWidget *parent)
  64. : QWidget(parent), currentMovie(0)
  65. {
  66. HIViewRef movieView;
  67. HIObjectCreate(kHIMovieViewClassID, 0, reinterpret_cast<HIObjectRef*>(&movieView));
  68. HIMovieViewChangeAttributes(movieView,
  69. kHIMovieViewAutoIdlingAttribute | kHIMovieViewControllerVisibleAttribute, 0);
  70.  
  71. create(WId(movieView));
  72. setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
  73.  
  74. }
  75.  
  76. MovieWidget::~MovieWidget()
  77. {
  78. if (currentMovie)
  79. DisposeMovie(currentMovie);
  80. }
  81.  
  82. void MovieWidget::dispose()
  83. {
  84. if (currentMovie)
  85. DisposeMovie(currentMovie);
  86. }
  87.  
  88. void MovieWidget::loadMovie(const QString &fileName)
  89. {
  90. QTVisualContextRef visualContext = 0;
  91. Boolean active = true;
  92. DataReferenceRecord dataRef;
  93. Movie oldMovie = 0;
  94.  
  95.  
  96.  
  97. // create an array of properties for NewMovieFromProperties
  98. // these properties describe how to create the new movie
  99. // see Movies.h for the full list of available properties
  100. QTNewMoviePropertyElement newMovieProperties[] = {
  101. {kQTPropertyClass_DataLocation, kQTDataLocationPropertyID_DataReference, sizeof(dataRef), &dataRef, 0},
  102. {kQTPropertyClass_NewMovieProperty, kQTNewMoviePropertyID_Active, sizeof(active), &active, 0},
  103. {kQTPropertyClass_Context, kQTContextPropertyID_VisualContext, sizeof(visualContext), &visualContext, 0},
  104. };
  105.  
  106. CFStringRef cfString = CFStringCreateWithCharacters(0,
  107. reinterpret_cast<const UniChar *>(fileName.unicode()),
  108. fileName.length());
  109. QTNewDataReferenceFromFullPathCFString(cfString, kQTPOSIXPathStyle, 0, &dataRef.dataRef, &dataRef.dataRefType);
  110. CFRelease(cfString);
  111.  
  112.  
  113. // if there's an old movie save it so we can dispose of it if
  114. // we load up a new movie successfully
  115. oldMovie = currentMovie;
  116. currentMovie = 0;
  117.  
  118. // create a new movie using movie properties
  119. // when calling this function, you supply a set of input properties that describe the information
  120. // required to instantiate the movie (its data reference, audio context, visual context, and so on)
  121. NewMovieFromProperties(sizeof(newMovieProperties) / sizeof(newMovieProperties[0]), // the number of properties in the array passed in inputProperties
  122. newMovieProperties, // a pointer to a property array describing how to instantiate the movie
  123. 0, // number of properties in the array passed in outputProperties
  124. 0, // pointer to a property array to receive output parameters - 0 if you don’t want this information
  125. &currentMovie); // pointer to a variable that receives the new movie
  126. // make sure to dispose of the dataRef we no longer need it
  127. DisposeHandle(dataRef.dataRef);
  128.  
  129. // set the HIMovieView's current movie
  130. HIMovieViewSetMovie(HIViewRef(winId()), currentMovie);
  131.  
  132. if (oldMovie != 0)
  133. DisposeMovie(oldMovie);
  134.  
  135. if(currentMovie == 0)
  136. emit NoPreview();
  137. // new movie has a new size, need to update.
  138. updateGeometry();
  139. emit optimalSizeChange();
  140.  
  141. }
  142.  
  143. QSize MovieWidget::sizeHint() const
  144. {
  145. EventRef event;
  146. HIRect optimalBounds;
  147. CreateEvent(0, kEventClassControl, kEventControlGetOptimalBounds,
  148. GetCurrentEventTime(), kEventAttributeUserEvent, &event);
  149. SendEventToEventTargetWithOptions(event,
  150. HIObjectGetEventTarget(HIObjectRef(winId())),
  151. kEventTargetDontPropagate);
  152. GetEventParameter(event, kEventParamControlOptimalBounds, typeHIRect,
  153. 0, sizeof(HIRect), 0, &optimalBounds);
  154. ReleaseEvent(event);
  155. return QSize(optimalBounds.size.width, optimalBounds.size.height);
  156. }
  157.  
  158. bool MovieWidget::nativeControlsVisible() const
  159. {
  160. OptionBits currentBits = HIMovieViewGetAttributes(HIViewRef(winId()));
  161. return currentBits & kHIMovieViewControllerVisibleAttribute;
  162. }
  163.  
  164. void MovieWidget::setNativeControlsVisible(bool visible)
  165. {
  166. if (visible != nativeControlsVisible()) {
  167. HIMovieViewChangeAttributes(HIViewRef(winId()),
  168. visible ? kHIMovieViewControllerVisibleAttribute : 0,
  169. !visible ? kHIMovieViewControllerVisibleAttribute : 0);
  170. updateGeometry();
  171. emit optimalSizeChange();
  172.  
  173. }
  174. }
To copy to clipboard, switch view to plain text mode 


Regards
Merry