修正延迟释放的错误

This commit is contained in:
codeboss 2024-02-10 15:28:19 +08:00
parent 1ef520d6e8
commit 17335aca05
3 changed files with 13 additions and 11 deletions

View File

@ -17,11 +17,12 @@
using namespace split_window; using namespace split_window;
using namespace split_frame; using namespace split_frame;
SplitWindow::SplitWindow(QWidget *parent) : QMainWindow(parent), accept_port(new accept_panel::AcceptPanel(this, this)), view_root(nullptr) { SplitWindow::SplitWindow(QWidget *parent)
: QMainWindow(parent), active(true), accept_port(new accept_panel::AcceptPanel(this, this)), view_root(nullptr) {
accept_port->setVisible(false); accept_port->setVisible(false);
} }
SplitWindow::~SplitWindow() {} SplitWindow::~SplitWindow() {this->active = false;}
void SplitWindow::tempShow(split_frame::DockType t, split_frame::ViewBase *target) void SplitWindow::tempShow(split_frame::DockType t, split_frame::ViewBase *target)
{ {
@ -97,13 +98,13 @@ void SplitWindow::removeListener(split_frame::FreedomViewsListener *lsn)
void SplitWindow::appendPresentView(split_frame::ViewBase *inst) void SplitWindow::appendPresentView(split_frame::ViewBase *inst)
{ {
if(inst) if(this->active && inst)
this->presents_store[inst->hashCode()] = inst; this->presents_store[inst->hashCode()] = inst;
} }
void SplitWindow::removePresentView(split_frame::ViewBase *inst) void SplitWindow::removePresentView(split_frame::ViewBase *inst)
{ {
if(inst) if(this->active && inst)
this->presents_store.remove(inst->hashCode()); this->presents_store.remove(inst->hashCode());
} }

View File

@ -18,6 +18,7 @@ namespace split_window {
typedef float width; typedef float width;
private: private:
bool active = false;
QList<split_frame::FreedomViewsListener*> listener_list; QList<split_frame::FreedomViewsListener*> listener_list;
QHash<qulonglong, split_frame::ViewBase*> presents_store; QHash<qulonglong, split_frame::ViewBase*> presents_store;

View File

@ -18,15 +18,15 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QApplication a(argc, argv); QApplication a(argc, argv);
auto w = new split_window::SplitWindow; split_window::SplitWindow w;
auto spb = new split_panel::SplitPanel(w, split_frame::SplitType::SPLIT_H_LFIRST); auto spb = new split_panel::SplitPanel(&w, split_frame::SplitType::SPLIT_H_LFIRST);
auto bview = new dock_panel::DockableView(w, new QWidget, true); auto bview = new dock_panel::DockableView(&w, new QWidget, true);
auto dview = new dock_panel::DockableView(w, new QWidget, true); auto dview = new dock_panel::DockableView(&w, new QWidget, true);
spb->initViews(bview, dview); spb->initViews(bview, dview);
w->setPresentTarget(spb); w.setPresentTarget(spb);
a.installEventFilter(w); a.installEventFilter(&w);
w->show(); w.show();
return a.exec(); return a.exec();
} }