Review Request 122105: Fix KgDifficulty saving on app close
faure at kde.org
Fri Jan 23 22:39:17 UTC 2015
On Monday 19 January 2015 21:43:41 Albert Astals Cid wrote:
> It has a
> K_GLOBAL_STATIC(KgDifficulty, g_difficulty)
> and a
> KConfigGroup cg(KGlobal::config(), "KgDifficulty");
> cg.writeEntry("Level", currentLevel()->key());
> in KgDifficulty destructor.
> And it did work :D
OK. So I investigated it further and .... well, it worked through luck, mostly
As you probably heard before, the order of destruction of global statics is
not something one should rely upon. But that's exactly what happened here.
If the global static is created before KGlobal then it's destroyed afterwards,
and asserts. If it's created after KGlobal then no problem.
Since KGlobal was created in many automatic ways in kdelibs4, all apps ended
up in the second case, which is why it worked.
=> working kdelibs4 testcase
In KF5 it gives the QCoreApplication::arguments issue, but works otherwise.
Therefore one possible fix is ... calling KSharedConfig::openConfig() in
main(), or at least before calling the code that ends up creating your
singleton. Tricky (not really intuitive).
Here's the fix for the QCoreApplication::arguments issue:
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5
More information about the Kde-frameworks-devel