1
Usage of Amarok::config()
2
-------------------------
3
We provide this method for convenience, but it is important to use it properly. By
4
inspection, we can see that we may produce very obscure bugs in the wrong case:
5
6
 | KConfig
7
 | *config( const QString &group )
8
 | {
9
 |    //Slightly more useful config() that allows setting the group simultaneously
10
 |    KGlobal::config()->setGroup( group );
11
 |    return KGlobal::config();
12
 | }
13
14
Take the following example:
15
16
 | void
17
 | f1()
18
 | {
19
 |    KConfig *config = Amarok::config( "Group 2" );
20
 |    config->writeEntry( "Group 2 Variable", true );
21
 | }
22
 |
23
 | void
24
 | doStuff()
25
 | {
26
 |   KConfig *config = Amarok::config( "Group 1" );
27
 |   f1();
28
 |   config->writeEntry( "Group 1 Variable", true );
29
 | }
30
31
We would expect the following results:
32
33
 | [Group 1]
34
 | Group 1 Variable = true
35
 |
36
 | [Group 2]
37
 | Group 2 Variable = true
38
39
However because the config group is changed before writing the entry:
40
 | [Group 1]
41
 |
42
 | [Group 2]
43
 | Group 1 Variable = true
44
 | Group 2 Variable = true
45
46
Which is clearly incorrect. And hard to see when your wondering why f1() is not
47
working. So do not store a value of Amarok::config, make it a habit to just 
48
always call writeEntry or readEntry directly.
49
50
Correct:
51
 | amarok::config( "Group 1" )->writeEntry( "Group 1 Variable", true );