Hi all,
my program is crashing when destroying its children. I've noticed that is first deletes itself and then its children, but I can't find out the solution

mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include "playerwindow.h"
  6.  
  7. namespace Ui {
  8. class MainWindow;
  9. }
  10.  
  11. class MainWindow : public QMainWindow
  12. {
  13. Q_OBJECT
  14.  
  15. public:
  16. explicit MainWindow(QWidget *parent = 0);
  17. ~MainWindow();
  18.  
  19. private:
  20. Ui::MainWindow *ui;
  21. PlayerWindow *playerWindow;
  22.  
  23. void keyPressEvent(QKeyEvent *event);
  24. };
  25.  
  26. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <qdebug.h>
  4. #include <QKeyEvent>
  5. #include <VLCQtCore/Common.h>
  6.  
  7. MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
  8. {
  9. ui->setupUi(this);
  10. }
  11.  
  12.  
  13. MainWindow::~MainWindow()
  14. {
  15. qDebug() << "destructed main";
  16. delete playerWindow;
  17. delete ui;
  18. }
  19.  
  20. void MainWindow::keyPressEvent(QKeyEvent *event)
  21. {
  22. switch (event->key()) {
  23. case Qt::Key_Return: case Qt::Key_Enter:
  24. playerWindow = new PlayerWindow(this);
  25. playerWindow->show();
  26.  
  27. break;
  28. case Qt::Key_Escape:
  29. this->close();
  30.  
  31. break;
  32. }
  33. }
To copy to clipboard, switch view to plain text mode 

playerwindow.h
Qt Code:
  1. #ifndef PLAYERWINDOW_H
  2. #define PLAYERWINDOW_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. namespace Ui {
  7. class PlayerWindow;
  8. }
  9.  
  10. class VlcInstance;
  11. class VlcMedia;
  12. class VlcMediaPlayer;
  13.  
  14. class PlayerWindow : public QMainWindow
  15. {
  16. Q_OBJECT
  17.  
  18. public:
  19. explicit PlayerWindow(QWidget *parent = 0);
  20. ~PlayerWindow();
  21.  
  22. private slots:
  23. void openFile();
  24.  
  25. private:
  26. Ui::PlayerWindow *ui;
  27.  
  28. VlcInstance *_instance;
  29. VlcMedia *_media;
  30. VlcMediaPlayer *_player;
  31.  
  32. void keyPressEvent(QKeyEvent *event);
  33. };
  34.  
  35. #endif // PLAYERWINDOW_H
To copy to clipboard, switch view to plain text mode 
playerwindow.cpp
Qt Code:
  1. #include "playerwindow.h"
  2. #include "ui_playerwindow.h"
  3.  
  4. #include <VLCQtCore/Common.h>
  5. #include <VLCQtCore/Instance.h>
  6. #include <VLCQtCore/Media.h>
  7. #include <VLCQtCore/MediaPlayer.h>
  8. #include <QKeyEvent>
  9. #include <QDebug>
  10.  
  11. PlayerWindow::PlayerWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::PlayerWindow)
  12. {
  13. ui->setupUi(this);
  14.  
  15. _instance = new VlcInstance(VlcCommon::args(), this);
  16. _player = new VlcMediaPlayer(_instance);
  17. _player->setVideoWidget(ui->video);
  18.  
  19. ui->video->setMediaPlayer(_player);
  20. ui->seek->setMediaPlayer(_player);
  21. }
  22.  
  23.  
  24. PlayerWindow::~PlayerWindow()
  25. {
  26. qDebug() << "destructed player";
  27. delete _player;
  28. delete _media;
  29. delete _instance;
  30.  
  31. delete ui;
  32. }
  33.  
  34. void PlayerWindow::openFile()
  35. {
  36. QString file = "/home/test/Video/VID_20160822_124845.mp4";
  37. _media = new VlcMedia(file, true, _instance);
  38. _player->open(_media);
  39. }
  40.  
  41. void PlayerWindow::keyPressEvent(QKeyEvent *event)
  42. {
  43. if(event->key() == Qt::Key_Escape){
  44. _player->stop();
  45. this->hide();
  46. }
  47. else if(event->key() == Qt::Key_Space){
  48. openFile();
  49. }
  50. }
To copy to clipboard, switch view to plain text mode