1 | //! [0]
|
---|
2 | Q3IntDict<QLineEdit> fields; // long int keys, QLineEdit* values
|
---|
3 | for ( int i = 0; i < 3; i++ )
|
---|
4 | fields.insert( i, new QLineEdit( this ) );
|
---|
5 |
|
---|
6 | fields[0]->setText( "Homer" );
|
---|
7 | fields[1]->setText( "Simpson" );
|
---|
8 | fields[2]->setText( "45" );
|
---|
9 |
|
---|
10 | Q3IntDictIterator<QLineEdit> it( fields );
|
---|
11 | for ( ; it.current(); ++it )
|
---|
12 | cout << it.currentKey() << ": " << it.current()->text() << endl;
|
---|
13 |
|
---|
14 | for ( int i = 0; i < 3; i++ )
|
---|
15 | cout << fields[i]->text() << " "; // Prints "Homer Simpson 45"
|
---|
16 | cout << endl;
|
---|
17 |
|
---|
18 | fields.remove( 1 ); // Does not delete the line edit
|
---|
19 | for ( int i = 0; i < 3; i++ )
|
---|
20 | if ( fields[i] )
|
---|
21 | cout << fields[i]->text() << " "; // Prints "Homer 45"
|
---|
22 | //! [0]
|
---|
23 |
|
---|
24 |
|
---|
25 | //! [1]
|
---|
26 | Q3IntDict<char> dict;
|
---|
27 | // ...
|
---|
28 | if ( dict.find(key) )
|
---|
29 | dict.remove( key );
|
---|
30 | dict.insert( key, item );
|
---|
31 | //! [1]
|
---|
32 |
|
---|
33 |
|
---|
34 | //! [2]
|
---|
35 | Q3IntDict<QLineEdit> fields;
|
---|
36 | for ( int i = 0; i < 3; i++ )
|
---|
37 | fields.insert( i, new QLineEdit( this ) );
|
---|
38 |
|
---|
39 | fields[0]->setText( "Homer" );
|
---|
40 | fields[1]->setText( "Simpson" );
|
---|
41 | fields[2]->setText( "45" );
|
---|
42 |
|
---|
43 | Q3IntDictIterator<QLineEdit> it( fields );
|
---|
44 | for ( ; it.current(); ++it )
|
---|
45 | cout << it.currentKey() << ": " << it.current()->text() << endl;
|
---|
46 |
|
---|
47 | // Output (random order):
|
---|
48 | // 0: Homer
|
---|
49 | // 1: Simpson
|
---|
50 | // 2: 45
|
---|
51 | //! [2]
|
---|