source: trunk/doc/src/snippets/code/doc_src_q3asciidict.qdoc@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 1.4 KB
Line 
1//! [0]
2Q3AsciiDict<QLineEdit> fields; // char* keys, QLineEdit* values
3fields.insert( "forename", new QLineEdit( this ) );
4fields.insert( "surname", new QLineEdit( this ) );
5
6fields["forename"]->setText( "Homer" );
7fields["surname"]->setText( "Simpson" );
8
9Q3AsciiDictIterator<QLineEdit> it( fields ); // See Q3AsciiDictIterator
10for( ; it.current(); ++it )
11 cout << it.currentKey() << ": " << it.current()->text() << endl;
12cout << endl;
13
14if ( fields["forename"] && fields["surname"] )
15 cout << fields["forename"]->text() << " "
16 << fields["surname"]->text() << endl; // Prints "Homer Simpson"
17
18fields.remove( "forename" ); // Does not delete the line edit
19if ( ! fields["forename"] )
20 cout << "forename is not in the dictionary" << endl;
21//! [0]
22
23
24//! [1]
25Q3AsciiDict<char> dict;
26 ...
27if ( dict.find(key) )
28 dict.remove( key );
29dict.insert( key, item );
30//! [1]
31
32
33//! [2]
34Q3AsciiDict<QLineEdit> fields;
35fields.insert( "forename", new QLineEdit( this ) );
36fields.insert( "surname", new QLineEdit( this ) );
37fields.insert( "age", new QLineEdit( this ) );
38
39fields["forename"]->setText( "Homer" );
40fields["surname"]->setText( "Simpson" );
41fields["age"]->setText( "45" );
42
43Q3AsciiDictIterator<QLineEdit> it( fields );
44for( ; it.current(); ++it )
45 cout << it.currentKey() << ": " << it.current()->text() << endl;
46cout << endl;
47
48// Output (random order):
49// age: 45
50// surname: Simpson
51// forename: Homer
52//! [2]
Note: See TracBrowser for help on using the repository browser.