I have interesting example. We are have qml form, and button. After click need close window and delete window. Simple. But application stable crash. Example:

main.cpp
Qt Code:
  1. #include <QApplication>
  2.  
  3. #include "windowmanager.h"
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. * *QApplication a(argc, argv);
  8.  
  9. * *WindowManager manager;
  10. * *manager.showWindow();
  11.  
  12. * *return a.exec();
  13. }
To copy to clipboard, switch view to plain text mode 

windowmanager.h
Qt Code:
  1. #ifndef WINDOWMANAGER_H
  2. #define WINDOWMANAGER_H
  3.  
  4. #include <QObject>
  5. #include <QDeclarativeView>
  6.  
  7. class WindowManager : public QObject
  8. {
  9. * *Q_OBJECT
  10. * *public:
  11. * * * *explicit WindowManager(QObject *parent = 0);
  12.  
  13. * * * *void showWindow();
  14. * * * *Q_INVOKABLE void closeWindow();
  15.  
  16. * * * *QDeclarativeView *window();
  17.  
  18. * *private:
  19. * * * *QDeclarativeView *m_window;
  20.  
  21. };
  22.  
  23. #endif // WINDOWMANAGER_H
To copy to clipboard, switch view to plain text mode 


windowmanager.cpp
Qt Code:
  1. #include "windowmanager.h"
  2.  
  3. #include <QDeclarativeContext>
  4.  
  5. WindowManager::WindowManager(QObject *parent) : QObject(parent), m_window(0)
  6. {
  7. }
  8.  
  9. void WindowManager::showWindow()
  10. {
  11. * *window()->show();
  12. }
  13.  
  14. void WindowManager::closeWindow()
  15. {
  16. * *m_window->close();
  17.  
  18. * *if (m_window != 0) {
  19. * * * *delete m_window;
  20. * * * *m_window = 0;
  21. * *}
  22. }
  23.  
  24. QDeclarativeView *WindowManager::window()
  25. {
  26. * *if (m_window == 0) {
  27. * * * *m_window = new QDeclarativeView(0);
  28.  
  29. * * * *m_window->rootContext()->setContextProperty("manager",this);
  30. * * * *m_window->setSource(QUrl("qrc:/main.qml"));
  31. * *}
  32.  
  33. * *return m_window;
  34. }
To copy to clipboard, switch view to plain text mode 

main.qml
Qt Code:
  1. import QtQuick 1.1
  2.  
  3. Item {
  4. * *width: 500
  5. * *height: 500
  6.  
  7. * *Rectangle {
  8. * * * *width: 200
  9. * * * *height: 200
  10.  
  11. * * * *anchors.centerIn: parent
  12.  
  13. * * * *color: "red"
  14.  
  15. * * * *Text {
  16. * * * * * *anchors.centerIn: parent
  17. * * * * * *color: "white"
  18.  
  19. * * * * * *text: "Click for crash"
  20. * * * *}
  21.  
  22. * * * *MouseArea {
  23. * * * * * *anchors.fill: parent
  24.  
  25. * * * * * *onClicked: {
  26. * * * * * * * *manager.closeWindow();
  27. * * * * * *}
  28. * * * *}
  29. * *}
  30. }
To copy to clipboard, switch view to plain text mode 

If i use, deleteLater() then applicaition crash in 20% users. If i user hotkey for delete window, all work is good, but why app crash in click button?