subsurface/desktop-widgets/statswidget.h
Dirk Hohndel 2368a183e1 Qt6: prevent QML object from being garbage collected
It appears that the QML object that is created when assigning the source
to the StatsView in the ui can be garbage collected and therefore
destroyed and re-instantiated without our knowledge. So instead of
trying to keep a pointer around, we end up looking up the object address
when needed.
We still ask the JS code to not garbage collect the object - but that
clearly isn't enough to prevent it from being destroyed when the parent
widget changes.

Without this fix opening the statistics will crash with Qt6.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-03-12 08:28:32 -08:00

44 lines
945 B
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef STATSWIDGET_H
#define STATSWIDGET_H
#include "stats/statsstate.h"
#include "stats/chartlistmodel.h"
#include "ui_statswidget.h"
#include <vector>
#include <memory>
class QCheckBox;
class StatsView;
class StatsWidget : public QWidget {
Q_OBJECT
public:
StatsWidget(QWidget *parent = 0);
private
slots:
void closeStats();
void chartTypeChanged(int);
void var1Changed(int);
void var2Changed(int);
void var1BinnerChanged(int);
void var2BinnerChanged(int);
void var2OperationChanged(int);
void var1SortChanged(int);
void featureChanged(int, bool);
void restrict();
void unrestrict();
private:
Ui::StatsWidget ui;
StatsState state;
StatsView *getView();
void updateUi();
void updateRestrictionLabel();
std::vector<std::unique_ptr<QCheckBox>> features;
ChartListModel charts;
void showEvent(QShowEvent *) override;
void hideEvent(QHideEvent *) override;
};
#endif // STATSWIDGET_H