From e9ebc8d8c33d791bcb1a18dab18b0fdd0dc2de95 Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Mon, 18 Jun 2018 10:27:13 +0200 Subject: [PATCH] fix qml binding auto parent --- src/imports/mvvmcore/qqmlmvvmbinding.cpp | 14 ++++---------- src/imports/mvvmcore/qqmlmvvmbinding.h | 8 ++++---- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/imports/mvvmcore/qqmlmvvmbinding.cpp b/src/imports/mvvmcore/qqmlmvvmbinding.cpp index c08d271..e8e9cc0 100644 --- a/src/imports/mvvmcore/qqmlmvvmbinding.cpp +++ b/src/imports/mvvmcore/qqmlmvvmbinding.cpp @@ -1,18 +1,10 @@ #include "qqmlmvvmbinding.h" using namespace QtMvvm; +#include QQmlMvvmBinding::QQmlMvvmBinding(QObject *parent) : QObject(parent), - QQmlParserStatus(), - _binding(), - _completed(false), - _viewModel(nullptr), - _viewModelProperty(), - _view(parent), - _viewProperty(), - _type(TwoWay), - _viewModelChangeSignal(), - _viewChangeSignal() + QQmlParserStatus() { connect(this, &QQmlMvvmBinding::viewModelChanged, this, &QQmlMvvmBinding::resetBinding); @@ -30,6 +22,8 @@ void QQmlMvvmBinding::classBegin() {} void QQmlMvvmBinding::componentComplete() { + if(!_view) + _view = parent(); _completed = true; resetBinding(); } diff --git a/src/imports/mvvmcore/qqmlmvvmbinding.h b/src/imports/mvvmcore/qqmlmvvmbinding.h index 4fcb3fd..333b372 100644 --- a/src/imports/mvvmcore/qqmlmvvmbinding.h +++ b/src/imports/mvvmcore/qqmlmvvmbinding.h @@ -159,13 +159,13 @@ private Q_SLOTS: private: Binding _binding; - bool _completed; + bool _completed = false; - QObject* _viewModel; + QObject* _viewModel = nullptr; QString _viewModelProperty; - QObject* _view; + QObject* _view = nullptr; QString _viewProperty; - BindingDirection _type; + BindingDirection _type = TwoWay; QString _viewModelChangeSignal; QString _viewChangeSignal; };