kmediaplayer: use QPointer<T> to store the KMediaWidget pointer

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-26 20:44:13 +02:00
parent d874397ed4
commit 57be009258
2 changed files with 7 additions and 2 deletions

View file

@ -22,6 +22,7 @@
#include <KLocale>
#include <KMessageBox>
#include <KPluginFactory>
#include <KDebug>
K_PLUGIN_FACTORY(KMediaPlayerPartFactory, registerPlugin<KMediaPlayerPart>();) // produce a factory
K_EXPORT_PLUGIN(KMediaPlayerPartFactory(KAboutData(
@ -45,12 +46,15 @@ KMediaPlayerPart::KMediaPlayerPart(QWidget *parentWidget, QObject *parent, const
Q_UNUSED(arguments);
setComponentData(KMediaPlayerPartFactory::componentData());
setWidget(m_player);
setAutoDeleteWidget(false); // will be deleted in destructor, if still valid
m_player->player()->setPlayerID("kmediaplayerpart");
}
KMediaPlayerPart::~KMediaPlayerPart()
{
delete m_player;
if (m_player) {
delete m_player.data();
}
}
bool KMediaPlayerPart::openUrl(const KUrl &url)

View file

@ -19,6 +19,7 @@
#ifndef KMEDIAPART_H
#define KMEDIAPART_H
#include <QPointer>
#include <KParts/Part>
#include <KMediaWidget>
#include <KUrl>
@ -37,7 +38,7 @@ public Q_SLOTS:
bool openUrl(const KUrl &url) final;
private:
KMediaWidget *m_player;
QPointer<KMediaWidget> m_player;
};
#endif // KMEDIAPART_H