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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "playerwindow.h"
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
PlayerWindow *playerWindow;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "playerwindow.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
PlayerWindow *playerWindow;
void keyPressEvent(QKeyEvent *event);
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qdebug.h>
#include <QKeyEvent>
#include <VLCQtCore/Common.h>
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
qDebug() << "destructed main";
delete playerWindow;
delete ui;
}
void MainWindow
::keyPressEvent(QKeyEvent *event
) {
switch (event->key()) {
case Qt::Key_Return: case Qt::Key_Enter:
playerWindow = new PlayerWindow(this);
playerWindow->show();
break;
case Qt::Key_Escape:
this->close();
break;
}
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qdebug.h>
#include <QKeyEvent>
#include <VLCQtCore/Common.h>
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
qDebug() << "destructed main";
delete playerWindow;
delete ui;
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Return: case Qt::Key_Enter:
playerWindow = new PlayerWindow(this);
playerWindow->show();
break;
case Qt::Key_Escape:
this->close();
break;
}
}
To copy to clipboard, switch view to plain text mode
playerwindow.h
#ifndef PLAYERWINDOW_H
#define PLAYERWINDOW_H
#include <QMainWindow>
namespace Ui {
class PlayerWindow;
}
class VlcInstance;
class VlcMedia;
class VlcMediaPlayer;
{
Q_OBJECT
public:
explicit PlayerWindow
(QWidget *parent
= 0);
~PlayerWindow();
private slots:
void openFile();
private:
Ui::PlayerWindow *ui;
VlcInstance *_instance;
VlcMedia *_media;
VlcMediaPlayer *_player;
};
#endif // PLAYERWINDOW_H
#ifndef PLAYERWINDOW_H
#define PLAYERWINDOW_H
#include <QMainWindow>
namespace Ui {
class PlayerWindow;
}
class VlcInstance;
class VlcMedia;
class VlcMediaPlayer;
class PlayerWindow : public QMainWindow
{
Q_OBJECT
public:
explicit PlayerWindow(QWidget *parent = 0);
~PlayerWindow();
private slots:
void openFile();
private:
Ui::PlayerWindow *ui;
VlcInstance *_instance;
VlcMedia *_media;
VlcMediaPlayer *_player;
void keyPressEvent(QKeyEvent *event);
};
#endif // PLAYERWINDOW_H
To copy to clipboard, switch view to plain text mode
playerwindow.cpp
#include "playerwindow.h"
#include "ui_playerwindow.h"
#include <VLCQtCore/Common.h>
#include <VLCQtCore/Instance.h>
#include <VLCQtCore/Media.h>
#include <VLCQtCore/MediaPlayer.h>
#include <QKeyEvent>
#include <QDebug>
PlayerWindow
::PlayerWindow(QWidget *parent
): QMainWindow(parent
), ui
(new Ui
::PlayerWindow){
ui->setupUi(this);
_instance = new VlcInstance(VlcCommon::args(), this);
_player = new VlcMediaPlayer(_instance);
_player->setVideoWidget(ui->video);
ui->video->setMediaPlayer(_player);
ui->seek->setMediaPlayer(_player);
}
PlayerWindow::~PlayerWindow()
{
qDebug() << "destructed player";
delete _player;
delete _media;
delete _instance;
delete ui;
}
void PlayerWindow::openFile()
{
QString file = "/home/test/Video/VID_20160822_124845.mp4";
_media = new VlcMedia(file, true, _instance);
_player->open(_media);
}
void PlayerWindow
::keyPressEvent(QKeyEvent *event
) {
if(event->key() == Qt::Key_Escape){
_player->stop();
this->hide();
}
else if(event->key() == Qt::Key_Space){
openFile();
}
}
#include "playerwindow.h"
#include "ui_playerwindow.h"
#include <VLCQtCore/Common.h>
#include <VLCQtCore/Instance.h>
#include <VLCQtCore/Media.h>
#include <VLCQtCore/MediaPlayer.h>
#include <QKeyEvent>
#include <QDebug>
PlayerWindow::PlayerWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::PlayerWindow)
{
ui->setupUi(this);
_instance = new VlcInstance(VlcCommon::args(), this);
_player = new VlcMediaPlayer(_instance);
_player->setVideoWidget(ui->video);
ui->video->setMediaPlayer(_player);
ui->seek->setMediaPlayer(_player);
}
PlayerWindow::~PlayerWindow()
{
qDebug() << "destructed player";
delete _player;
delete _media;
delete _instance;
delete ui;
}
void PlayerWindow::openFile()
{
QString file = "/home/test/Video/VID_20160822_124845.mp4";
_media = new VlcMedia(file, true, _instance);
_player->open(_media);
}
void PlayerWindow::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Escape){
_player->stop();
this->hide();
}
else if(event->key() == Qt::Key_Space){
openFile();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks