diff --git a/ui/drivers/qt/flowlayout.cpp b/ui/drivers/qt/flowlayout.cpp index 8f8ba5333a..b970e10b10 100644 --- a/ui/drivers/qt/flowlayout.cpp +++ b/ui/drivers/qt/flowlayout.cpp @@ -55,13 +55,14 @@ #include #include "flowlayout.h" +#include "../ui_qt.h" FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing) : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) { setContentsMargins(margin, margin, margin, margin); - connect(this, SIGNAL(signalAddWidgetDeferred(QWidget*)), this, SLOT(onAddWidgetDeferred(QWidget*)), Qt::QueuedConnection); + connect(this, SIGNAL(signalAddWidgetDeferred(QPointer)), this, SLOT(onAddWidgetDeferred(QPointer)), Qt::QueuedConnection); } FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing) @@ -226,18 +227,22 @@ int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const else if (parentObj->isWidgetType()) { const QWidget *pw = static_cast(parentObj); - return pw->style()->pixelMetric(pm, 0, pw); + return pw->style()->pixelMetric(pm, NULL, pw); } else return static_cast(parentObj)->spacing(); } -void FlowLayout::addWidgetDeferred(QWidget *widget) +void FlowLayout::addWidgetDeferred(QPointer widget) { emit signalAddWidgetDeferred(widget); } -void FlowLayout::onAddWidgetDeferred(QWidget *widget) +void FlowLayout::onAddWidgetDeferred(QPointer widget) { + /* widget might have been deleted before we got to it since this uses a queued connection, hence the guarded QPointer */ + if (!widget) + return; + addWidget(widget); } diff --git a/ui/drivers/qt/flowlayout.h b/ui/drivers/qt/flowlayout.h index 84dc349d51..c9d11e7653 100644 --- a/ui/drivers/qt/flowlayout.h +++ b/ui/drivers/qt/flowlayout.h @@ -63,6 +63,8 @@ #include #include +class ThumbnailWidget; + class FlowLayout : public QLayout { Q_OBJECT @@ -83,13 +85,13 @@ public: void setGeometry(const QRect &rect); QSize sizeHint() const; QLayoutItem* takeAt(int index); - void addWidgetDeferred(QWidget *widget); + void addWidgetDeferred(QPointer widget); signals: - void signalAddWidgetDeferred(QWidget *widget); + void signalAddWidgetDeferred(QPointer widget); private slots: - void onAddWidgetDeferred(QWidget *widget); + void onAddWidgetDeferred(QPointer widget); private: int doLayout(const QRect &rect, bool testOnly) const; diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index 6cac031241..56ed1c463b 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -126,7 +126,8 @@ static void scan_finished_handler(void *task_data, void *user_data, const char * #endif GridItem::GridItem() : - widget(NULL) + QObject() + ,widget(NULL) ,label(NULL) ,hash() ,image() @@ -545,6 +546,8 @@ MainWindow::MainWindow(QWidget *parent) : QAction *viewTypeListAction = NULL; int i = 0; + qRegisterMetaType >("ThumbnailWidget"); + viewTypePushButton->setObjectName("viewTypePushButton"); viewTypePushButton->setFlat(true); @@ -2895,13 +2898,13 @@ void MainWindow::removeGridItems() { if (m_gridItems.count() > 0) { - QMutableListIterator items(m_gridItems); + QMutableVectorIterator > items(m_gridItems); m_pendingItemUpdates.clear(); while (items.hasNext()) { - GridItem *item = items.next(); + QPointer item = items.next(); if (item) { @@ -3003,8 +3006,8 @@ void MainWindow::addPlaylistItemsToGrid(const QString &pathString) for (i = 0; i < items.count(); i++) { const QHash &hash = items.at(i); - GridItem *item = new GridItem(); - ThumbnailLabel *label = NULL; + QPointer item (new GridItem()); + QPointer label; QString thumbnailFileNameNoExt; QLabel *newLabel = NULL; QSize thumbnailWidgetSizeHint(screenSize.width() / 8, screenSize.height() / 8); diff --git a/ui/drivers/ui_qt.h b/ui/drivers/ui_qt.h index a035b355b1..42a404faca 100644 --- a/ui/drivers/ui_qt.h +++ b/ui/drivers/ui_qt.h @@ -31,6 +31,7 @@ #include #include #include +#include extern "C" { #include @@ -65,12 +66,14 @@ class ThumbnailWidget; class ThumbnailLabel; class FlowLayout; -struct GridItem +class GridItem : public QObject { + Q_OBJECT +public: GridItem(); - ThumbnailWidget *widget; - ThumbnailLabel *label; + QPointer widget; + QPointer label; QHash hash; QImage image; QPixmap pixmap; @@ -394,7 +397,7 @@ private: FlowLayout *m_gridLayout; QWidget *m_gridWidget; QScrollArea *m_gridScrollArea; - QList m_gridItems; + QVector > m_gridItems; QWidget *m_gridLayoutWidget; QSlider *m_zoomSlider; int m_lastZoomSliderValue; @@ -406,6 +409,8 @@ protected: void keyPressEvent(QKeyEvent *event); }; +Q_DECLARE_METATYPE(QPointer) + RETRO_BEGIN_DECLS typedef struct ui_application_qt