aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/doc_src_q3asciidict.qdoc
blob: e2c876afba5537807684c3811740245a3bd2971b (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
52
//! [0]
Q3AsciiDict<QLineEdit> fields; // char* keys, QLineEdit* values
fields.insert( "forename", new QLineEdit( this ) );
fields.insert( "surname", new QLineEdit( this ) );

fields["forename"]->setText( "Homer" );
fields["surname"]->setText( "Simpson" );

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

if ( fields["forename"] && fields["surname"] )
    cout << fields["forename"]->text() << " " 
	<< fields["surname"]->text() << endl;  // Prints "Homer Simpson"

fields.remove( "forename" ); // Does not delete the line edit
if ( ! fields["forename"] )
    cout << "forename is not in the dictionary" << endl;
//! [0]


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


//! [2]
Q3AsciiDict<QLineEdit> fields;
fields.insert( "forename", new QLineEdit( this ) );
fields.insert( "surname", new QLineEdit( this ) );
fields.insert( "age", new QLineEdit( this ) );

fields["forename"]->setText( "Homer" );
fields["surname"]->setText( "Simpson" );
fields["age"]->setText( "45" );

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

// Output (random order):
//	age: 45
//	surname: Simpson
//	forename: Homer
//! [2]