Refactor AboutToQuit.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-07-01 12:47:06 +03:00
parent 4ab84bce38
commit c536c40628
7 changed files with 34 additions and 7 deletions

View File

@ -486,6 +486,15 @@ bool MApplication::event(QEvent *e)
return VAbstractApplication::event(e); return VAbstractApplication::event(e);
} }
//---------------------------------------------------------------------------------------------------------------------
void MApplication::AboutToQuit()
{
// If try to use the method QApplication::exit program can't sync settings and show warning about QApplication
// instance. Solution is to call sync() before quit.
// Connect this slot with VApplication::aboutToQuit.
Settings()->sync();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MApplication::OpenSettings() void MApplication::OpenSettings()
{ {

View File

@ -85,6 +85,9 @@ protected:
virtual void InitTrVars() override; virtual void InitTrVars() override;
virtual bool event(QEvent *e) override; virtual bool event(QEvent *e) override;
protected slots:
virtual void AboutToQuit() override;
private slots: private slots:
void NewLocalSocketConnection(); void NewLocalSocketConnection();

View File

@ -709,6 +709,15 @@ bool VApplication::event(QEvent *e)
return VAbstractApplication::event(e); return VAbstractApplication::event(e);
} }
//---------------------------------------------------------------------------------------------------------------------
void VApplication::AboutToQuit()
{
// If try to use the method QApplication::exit program can't sync settings and show warning about QApplication
// instance. Solution is to call sync() before quit.
// Connect this slot with VApplication::aboutToQuit.
Settings()->sync();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief OpenSettings get acsses to application settings. * @brief OpenSettings get acsses to application settings.

View File

@ -82,6 +82,9 @@ protected:
virtual void InitTrVars() override; virtual void InitTrVars() override;
virtual bool event(QEvent *e) override; virtual bool event(QEvent *e) override;
protected slots:
virtual void AboutToQuit() override;
private: private:
Q_DISABLE_COPY(VApplication) Q_DISABLE_COPY(VApplication)
VTranslateVars *trVars; VTranslateVars *trVars;

View File

@ -41,6 +41,7 @@ class VTestSettings;
class TestVApplication : public VAbstractApplication class TestVApplication : public VAbstractApplication
{ {
Q_OBJECT
public: public:
TestVApplication(int &argc, char ** argv) TestVApplication(int &argc, char ** argv)
: VAbstractApplication(argc, argv), : VAbstractApplication(argc, argv),
@ -77,6 +78,11 @@ public:
{ {
m_trVars = trVars; m_trVars = trVars;
} }
protected slots:
virtual void AboutToQuit() override
{}
private: private:
Q_DISABLE_COPY(TestVApplication) Q_DISABLE_COPY(TestVApplication)
VTranslateVars *m_trVars; VTranslateVars *m_trVars;

View File

@ -100,13 +100,7 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv)
setAttribute(Qt::AA_UseHighDpiPixmaps); setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif #endif
connect(this, &QApplication::aboutToQuit, this, [this]() connect(this, &QApplication::aboutToQuit, this, &VAbstractApplication::AboutToQuit);
{
// If try to use the method QApplication::exit program can't sync settings and show warning about QApplication
// instance. Solution is to call sync() before quit.
// Connect this slot with VApplication::aboutToQuit.
Settings()->sync();
});
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -146,6 +146,9 @@ protected:
virtual void InitTrVars()=0; virtual void InitTrVars()=0;
protected slots:
virtual void AboutToQuit()=0;
private: private:
Q_DISABLE_COPY(VAbstractApplication) Q_DISABLE_COPY(VAbstractApplication)
Unit _patternUnit; Unit _patternUnit;