File indexing completed on 2022-11-29 18:25:10

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License version 2 as published by the Free Software Foundation.
0007 
0008     This library is distributed in the hope that it will be useful,
0009     but WITHOUT ANY WARRANTY; without even the implied warranty of
0010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011     Library General Public License for more details.
0012 
0013     You should have received a copy of the GNU Library General Public License
0014     along with this library; see the file COPYING.LIB.  If not, write to
0015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0016     Boston, MA 02110-1301, USA.
0017 
0018 */
0019 
0020 #include <QCoreApplication>
0021 #include <QtGlobal>
0022 #include <kcomponentdata.h>
0023 #include <ksharedconfig.h>
0024 #include <kconfiggroup.h>
0025 
0026 class Tester
0027 {
0028 public:
0029     void initConfig();
0030     ~Tester();
0031 
0032 private:
0033     KConfig *m_config;
0034 };
0035 
0036 void Tester::initConfig()
0037 {
0038     m_config = new KConfig("kconfigafterkglobaltest");
0039 }
0040 
0041 Q_GLOBAL_STATIC(Tester, globalTestObject)
0042 
0043 int main(int argc, char **argv)
0044 {
0045     Tester *t = globalTestObject();
0046     Q_UNUSED(t);
0047 
0048     QCoreApplication app(argc, argv);
0049     KComponentData componentData("kconfigafterkglobaltest");
0050 
0051     t->initConfig();
0052 }
0053 
0054 Tester::~Tester()
0055 {
0056     // the KGlobal K_GLOBAL_STATIC should already be deleted
0057     // If this fails, check that a new global static in kdecore didn't create KGlobal indirectly;
0058     // e.g. this can happen if someone writes 'static int s_area = KDebug::registerArea("foo");' in
0059     // a .cpp file, rather than using a function.
0060     Q_ASSERT(!KComponentData::hasMainComponent());
0061     KConfigGroup group = m_config->group("test");
0062     group.writeEntry("test", 1);
0063     delete m_config; // this calls KConfig::sync() which needs KLocale::global()
0064 }