OSDN Git Service

kmediaplayer: use QPointer<T> to store the KMediaWidget pointer
authorIvailo Monev <xakepa10@gmail.com>
Sat, 26 Nov 2022 18:44:13 +0000 (20:44 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Sat, 26 Nov 2022 18:44:13 +0000 (20:44 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kmediaplayer/kmediaplayerpart.cpp
kmediaplayer/kmediaplayerpart.h

index c76dd42..a139371 100644 (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)
index c6ada40..f154271 100644 (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