summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/code/doc_src_q3intdict.qdoc
blob: 0fae2c8545a79e330c9bb5d9461646578a994781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! [0]
Q3IntDict<QLineEdit> fields; // long int keys, QLineEdit* values
for ( int i = 0; i < 3; i++ )
    fields.insert( i, new QLineEdit( this ) );

fields[0]->setText( "Homer" );
fields[1]->setText( "Simpson" );
fields[2]->setText( "45" );

Q3IntDictIterator<QLineEdit> it( fields );
for ( ; it.current(); ++it )
    cout << it.currentKey() << ": " << it.current()->text() << endl;

for ( int i = 0; i < 3; i++ )
    cout << fields[i]->text() << " "; // Prints "Homer Simpson 45"
cout << endl;

fields.remove( 1 ); // Does not delete the line edit
for ( int i = 0; i < 3; i++ )
    if ( fields[i] )
	cout << fields[i]->text() << " "; // Prints "Homer 45"
//! [0]


//! [1]
Q3IntDict<char> dict;
//	...
if ( dict.find(key) )
    dict.remove( key );
dict.insert( key, item );
//! [1]


//! [2]
Q3IntDict<QLineEdit> fields;
for ( int i = 0; i < 3; i++ )
    fields.insert( i, new QLineEdit( this ) );

fields[0]->setText( "Homer" );
fields[1]->setText( "Simpson" );
fields[2]->setText( "45" );

Q3IntDictIterator<QLineEdit> it( fields ); 
for ( ; it.current(); ++it )
    cout << it.currentKey() << ": " << it.current()->text() << endl;

// Output (random order):
//	0: Homer
//	1: Simpson
//	2: 45
//! [2]