summaryrefslogtreecommitdiffstats
path: root/examples/qtl/qvaluelistiterator.cpp
blob: a9c65afa7c97da9da65e8f77f246da8a483e118e (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
53
54
55
56
57
/****************************************************************************
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include <qvaluelist.h>
#include <qstring.h>
#include <qwindowdefs.h>
#include <stdio.h>


class Employee
{
public:
    Employee(): s(0) {}
    Employee( const TQString& name, int salary )
	: n(name), s(salary) {}

    TQString name() const { return n; }

    int salary() const { return s; }
    void setSalary( int salary ) { s = salary; }

    // this is here to support very old compilers
    Q_DUMMY_COMPARISON_OPERATOR( Employee )

private:
    TQString n;
    int s;
};


int main( int, char** )
{
    typedef TQValueList<Employee> EmployeeList;
    EmployeeList list;

    list.append( Employee("Bill", 50000) );
    list.append( Employee("Steve",80000) );
    list.append( Employee("Ron",  60000) );

    Employee joe( "Joe", 50000 );
    list.append( joe );
    joe.setSalary( 4000 );

    EmployeeList::ConstIterator it = list.begin();
    while( it != list.end() ) {
	printf( "%s earns %d\n", (*it).name().latin1(), (*it).salary() );
	++it;
    }

    return 0;
}