Вы находитесь на странице: 1из 52

1.


++ -

- ,

= "" +

, ..

= +

+
,

..

QDate
QDate birthday(1990, 3, 23)

, ,
------------------- , ,

, ,

= 1990, = 3, = 23
------------------- , ,

, ,


()

birthday:

1990
3
23

, ,

birthday:
, ,
, ,

(,
)


,

:

< > < >;


:

QDate date; // // ,
6

, , , 23.03.1990

QDate birthday(1990, 3, 23);

//
//


,
.

++ ,

(
)

QDate

QDate () /* */
QDate ( int y, int m, int d ) /*
y, m
d*/

-
, :

< > < >


(< >);

10

QDate :

QDate ()
QDate ( int y, int m, int d )

, QDate:

QDate nullDate;

//

QDate birthday(1990, 3, 23);


11

//
//

QString ()
:

12

QString () /*
*/
QString ( const char * str ) /*
, ASCII
str*/
QString ( int size, char ch ) /*
size,
ch*/

str, "AAAAAAAAAAAAAAA" (15 )

// 1 -
QString str(15, 'A');
// 2
QString str("AAAAAAAAAAAAAAA");

13

14

,
,

, ,

QDate
:

bool setDate ( int year, int month, int day )


//

int weekNumber ( ) const


//

QDate :

15

bool isValid ( int year, int month, int day )


//



//
QDate date1(1991, 11, 15);
QDate date2(1991, 11, 15);
//
// date1
date1.setDate(2000, 12, 31);

//
// date2
int week = date2.weekNumber();

//
//
16 bool isValiDate = QDate::isValid(2000, 13, 45);

<>.< >(<>)

17


(
),

.


(
),

QString
int length () const


int strlen (const char *str)

QString str("Example"); char str[] = "Example";


int len = str.length(); int len = strlen(str);

18


QString :

QString & append ( const QString & str )

// str

QString FIO("");

//

QString fisrtName("");

//

QString name("");

//

QString patronymic("");

//

19

FIO ,
,

QString space(" ");

//

//

20

FIO.append(fisrtName);

//""

FIO.append(space);

//" "

FIO.append(name);

//" "

FIO.append(space);

//" "

FIO.append(patronymic);

//" "

,
,
,
<>.< 1_1>.< 2_1>
1_1 2

1
1_1
1_2

21

2
2_1
2_2
2_3

QDate

QString toString ( Qt::DateFormat format) const

// ,

QString

QString & prepend ( const QString & str )

//

QDate date(2009, 3, 23);


date.toString("dd.MM.yyyy").prepend("My birtday is ");
22

QString ("23.03.2009")

< >::< >(<>)

23


::


,

QString
int compare (
const QString & s1,
const QString & s2 )


int strcmp(
const char *s1,
const char *s2 )

QString str1("one");
QString str2("two");

char str1[] = "one";


char str2[] = "two";

int result =
int result =
QString::compare(str1,
strcmp(str1, str2);
str2);
24

QDate , :
QDate currentDate ()
,

QDate cDate;

25

QDate cDate;
//
cDate = QDate::currentDate();
,

26

QDate , :
QDate currentDate ()

int
int
int
int
int
int

27

day () const
dayOfWeek () const
dayOfYear () const
daysInMonth () const
daysInYear () const
daysTo ( const QDate & d ) const

- cyDays

int cyDays;
// -
cyDays = QDate::currentDate().daysInYear();
//

QDate cDate = QDate::currentDate();


cyDays = cDate.daysInYear();
28

++

29

++
, /

,

30

QString
:
QString & remove ( int position, int n )
// n , position
QString & remove ( const QString & str)
// str
QString & remove ( QChar ch)
// ch

QString str(", ");


QString cat("");
31 str.remove(1,1).remove(cat);

str.remove(1,1).remove(cat);

QString & remove ( int position, int n )


", "
QString & remove ( const QString & str )
", "

32

++ () (
+, =, [] ..)
. QDate
:

bool
bool
bool
bool
bool
33 bool

operator!=
operator<
operator<=
operator==
operator>
operator>=

(
(
(
(
(
(

const
const
const
const
const
const

QDate
QDate
QDate
QDate
QDate
QDate

&
&
&
&
&
&

d
d
d
d
d
d

)
)
)
)
)
)

const
const
const
const
const
const

QDate date1(2009, 3, 4);


QDate date2(2009, 4, 3);

34

date1 < date2;

//

date1.operator<(date2);

//

date1 == QDate::currentDate();

//



, , :

< > operator < >


(< >)

35

bool operator!= ( const QDate & d ) const


. , ..
,

,
:

< > operator < >


(< >, < >)

const QString operator+ ( char ch,


const QString & s )
QString str = 'A' + QString("BCD");
// str = "ABCD"
36

QString :
:

bool
bool
bool
bool

operator<
operator<
operator<
operator<

(const
(const
(const
(const

QString & other) const


QLatin1String & other) const
QByteArray & other) const
char * other) const

bool operator< (const char *s1, const QString &s2)

, :

QString str1(""), str2("");


str1 < str2; //1
37 '' < str1; //2

str1 < str2 , .. QString


bool operator< (const QString & other) const

38

'' < str1 , ..


, ,
,

++ ,



:

<> < >


(<> < > = < >)

39

QString ,
n :
QString & setNum ( int n, int base = 10 )

40

base ,
.
,
10:
QString str;
str.setNum(11, 2);
str.setNum(11);

// 1011
// 11


QString

int indexOf ( const QString & str, int from = 0,


Qt::CaseSensitivity cs = Qt::CaseSensitive ) const

/*
str */

QString str(", ");

"", ,
,
41

// ,
//
int index = str.indexOf( QString("") );

42

++
,
* -> &
:
< > &< >;

43

void swap(int *a, int *b)


{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}

void swap(int &a, int &b)


{
int tmp;
tmp = a;
a = b;
b = tmp;
}

void main(void)
{
int k = 5, m = 2;

void main(void)
{
int k = 5, m = 2;

swap(&k, &m); // k = 2,
// m = 5
44 }

swap(k, m);
}

// k = 2,
// m = 5

, ,
, .. , ,

:

int

compare

const

QString

&

other

const

//
QString str1(""), str2("");
str1.compare(str2);
45

, .

:

QString str("1234112");
str.remove("1").remove("2"); //str = "34"

str = "2342"

QString
&
remove
(
Qt::CaseSensitivity cs
46

const
QString
&
str,
= Qt::CaseSensitive )

//


< >(< >)
:

QString str =
QString(" ") + QString("");
47

QString

:
QDate
QString toString ( Qt::DateFormat format) const
// ,
QDate date(2007, 7, 7); //
QString str = date.toString("dd.MM.yyyy");
48

QString

49

++
new,
new (
):
new < >
:
new < >[<- >]
new malloc
( )

( )
delete:
delete
delete < >


:
delete [] < >

50

51

relations N
( QString),

-

int N = 5;

// -

// N
QString * relations = new QString[N];
//
relations[0] = QString(" ..");
// N
delete [] relations;
52

Вам также может понравиться