Qt中时间函数的使用

Qt中时间函数的使用
Qt中时间函数的使用

QTime::QTime()

默认构造函数,构造一个时,分,秒都为0的时间,如00:00:00.000(午夜)

QTime::QTime(int h, int m, int s=0, int ms = 0)

构造一个用户指定时,分,秒的时间.

其参数有效值为:

h:0--23

m:0--59

ms:0--999

QTime QTime::addMSecs(int ms) const

返回一个当前时间对象之后或之前ms毫秒的时间对象(之前还是之后视ms的符号,如为正则之后,反之之前)

如:QTime time(3,0,0);

QTime newTime1 = time.addMSecs(1000);

QTime newTime2 = time.addMSecs(-1000);

则newTime1是一个比time所指定时间(03:00:00.000)延后1000毫秒也即1秒的时间(03:00:01.000),而newTime2则提前1000毫秒(0 2:59:59.000)

QTime QTime::addSecs(int nsecs) const

与addMSecs()相同,只是nsecs单位是秒.即返回一个当前时间对象之前或之后的时间对象.

int QTime::elapsed() const

返回最后一次调用start()或restart()到现在已经经过的毫秒数.如果经过了24小时之后,则计数器置0.如果系统时间设置改变,则结果不确定.

int QTime::hour() const

返回时间对象的小时,取值范围(0--23)

int QTime::minute() const

返回时间对象的分钟,取值范围(0--59)

int QTime::second() const

返回时间对象的秒,取值范围(0--59)

int QTime::msec() const

返回时间对象的毫秒,取值范围(0--999)

bool QTime::isNull() const

如果时间对象等于00:00:00.000,则返回true;反之返回false.

bool QTime::isValid() const

如果时间对象是有效的,则返回true;反之返回false.(即:时,分,秒,毫秒都在其取值范围之内)

int QTime::msecsTo(const QTime &t) const

返回当前时间对象到t所指定的时间之间的毫秒数.如果t早于当前时间对象的时间,则返回的值是负值.因为一天的时间是86400000毫秒,所以返回值范围是-86400000--86400000

int QTime::secsTo(const QTime &t) const

与msecsTo()基本相同,只是返回的是秒数,返回值的有效范围是-86400--86400

int QTime::restart()

设置当前时间对象的值为当前系统时间,并且返回从最后一次调用start()或restart()到现在的毫秒数.如果计数器超出24小时,则置0.如果计数器计数时系统时间设置改变,则结果不确定.

bool QTime::setHMS(int h, int m, int s, int ms = 0)

设置当前时间对象的时,分,秒和毫秒.如果给定的参数值有效,则返回true,否则返回false.

void QTime::start()

设置当前时间对象的值为当前系统时间,这个函数实际是结合restart()和elapsed()用来计数的.

QString QTime::toString(const QString &format) const

按照参数format指定的格式用字符串形式输出当前时间对象的时间.

参数format用来指定时,分,秒,毫秒的输出格式.如(hh:mm:ss.zzz)

h:表示小时,范围是0--23

hh:用两位数表示小时,不足两位的前面用0补足,如(0点:00,3点:03,11点:11)

m:表示分钟,范围0--59

mm:用两位数表示分钟,不足两位的前面用0补足.

s:表示秒,范围0--59

ss:用两位数表示秒,不足两位的前面用0补足.

z:表示毫秒,范围0--999

zzz:用三位数表示毫秒,不足三位的前面用0补足.

AP:用AM/PM显示.

ap:用ap/pm显示.

例如:

QTime time(14,3,9,42);//设置时间为14:03:09.042

QString i = time.toString("hh:mm:ss.zzz");//结果为14:03:09.042

QString j = time.toString("h:m:s.z");//结果为14:3:9.42

QString m = time.toString("h:m:s.z AP");//结果为2:3:9.42 PM

QString n = time.toString("h:m:s.z ap");//结果为2:3:9.42 pm

QString QTime::toString(Qt::DateFormat f = Qt::TextDate) const

按照参数format指定的格式用字符串形式输出当前时间对象的时间.

参数的可选值:

Qt::TextDate:格式为HH:MM:SS

Qt::ISODate:遵循ISO8601的时间表示格式,同样也为HH:MM:SS

Qt::LocalDate:字符串格式依赖系统本地设置

----------------------------------------------------------------------------------------------------------------------------------------

静态成员函数:

QTime QTime::currentTime()

返回当前的系统时间.

QTime QTime::fromString(const QString &string, Qt::DateFormat format = Qt::TextDate)

使用参数format指定的格式根据参数string指定的时间返回一个时间对象。如果string指定的时间不合法,则返回一个无效的时间对象。

format可选值:

Qt::TextDate:格式为HH:MM:SS

Qt::ISODate:遵循ISO8601的时间表示格式,同样也为HH:MM:SS

Qt::LocalDate:字符串格式依赖系统本地设置

QTime QTime::fromString(const QString &string, const QString &format)

使用参数format指定的格式根据参数string指定的时间返回一个时间对象.如果string指定的时间不合法,则返回一个无效的时间对象.

format的格式参看QString QTime::toString(const QString &format) const.

bool QTime::isValid(int h, int m, int s, int ms = 0)

如果参数所指定的时间是合法的,则返回true;反之返回false.

----------------------------------------------------------------------------------------------------------------------------------------

静态成员函数不依赖于对象,可以通过类直接调用,与对象无关:

如:获取当前系统时间的小时部分时不需要定义QTime对象

int hour = QTime::currentTime().hour()

QTime类参考

QTime类提供了时钟时间功能。详情请见……

#include

所有成员函数的列表。

公有成员

?QTime ()

?QTime ( int h, int m, int s = 0, int ms = 0 )

?bool isNull () const

?bool isValid () const

?int hour () const

?int minute () const

?int second () const

?int msec () const

?QString toString ( Qt::DateFormat f = Qt::TextDate ) const

?QString toString ( const QString & format ) const

?bool setHMS ( int h, int m, int s, int ms = 0 )

?QTime addSecs ( int nsecs ) const

?int secsTo ( const QTime & t ) const

?QTime addMSecs ( int ms ) const

?int msecsTo ( const QTime & t ) const

?bool operator== ( const QTime & t ) const

?bool operator!= ( const QTime & t ) const

?bool operator< ( const QTime & t ) const

?bool operator<= ( const QTime & t ) const

?bool operator> ( const QTime & t ) const

?bool operator>= ( const QTime & t ) const

?void start ()

?int restart ()

?int elapsed () const

静态公有成员

?QTime currentTime ()

?QTime fromString ( const QString & s, Qt::DateFormat f = Qt::TextDate )

?bool isValid ( int h, int m, int s, int ms = 0 )

相关函数

?QDataStream &operator<< ( QDataStream & s, const QTime & t )

?QDataStream &operator>> ( QDataStream & s, QTime & t )

详细描述

QTime类提供了时钟时间功能。

QTime对象包含时钟时间,比如从午夜开始的时、分、秒和毫秒数。它可以从系统时钟中读取当前的时间并且度量时间的跨度。它提供比较时间和操作时间的函数,比如加上一定的秒或毫秒。

QTime操作的是24小时时钟格式,它没有AM/PM概念。它操作的是本地时间,它不知道有关时区或白天时间的概念。

QTime对象通常可以由明白地给定的时、分、秒和毫秒数字来创建,或者使用静态函数currentTime()让QTime对象包含系统时钟时间。注意精确性取决于下面操作系统的精确性,不是所有的操作系统都有毫秒级精确度的。

hour()、minute()、second()和msec()函数提供了对时、分、秒和毫秒数字的访问。toString()提供了文本格式的相同信息。

QTime提供了一整套的操作符来比较两个QTime对象,在这里小于表示早一些,大于表示晚一些。

一个给定时间之后给定的秒或毫秒数的时间可以使用addSecs()或addMSecs()得到。相对地,两个时间的秒(或毫秒)数可以使用secsTo()或msecsTo()得到。

QTime可以使用start()、restart()和elapsed()函数度量流逝的时间。

也可以参考QDate、QDateTime和时间和日期。

成员函数文档

QTime::QTime ()

构造一个时、分、秒和毫秒都是0的时间,比如,00:00:00.000(午夜)。这是一个有效的时间。也可以参考isValid()。

QTime::QTime ( int h, int m, int s = 0, int ms = 0 )

构造一个时、分、秒和毫秒分别为h、m、s和ms的时间。

h必须在0-23之间,m和s必须在0-59之间,ms必须在0-999之间。

也可以参考isValid()。

QTime QTime::addMSecs ( int ms ) const

返回这个时间对象ms毫秒之后的一个时间对象(或者ms毫秒之前的,如果它是一个负数)。注意如果这个时间过了午夜,它将被转换。请参考addSecs()中的实例。

也可以参考addSecs()和msecsTo()。

QTime QTime::addSecs ( int nsecs ) const

返回这个时间对象nsecs秒之后的一个时间对象(或者nsecs秒之前的,如果它是一个负数)。注意如果这个时间过了午夜,它将被转换。

实例:

QTime n( 14, 0, 0 ); // n == 14:00:00

QTime t;

t = n.addSecs( 70 ); // t == 14:01:10

t = n.addSecs( -70 ); // t == 13:58:50

t = n.addSecs( 10*60*60 + 5 ); // t == 00:00:05

t = n.addSecs( -15*60*60 ); // t == 23:00:00

也可以参考addMSecs()、secsTo()和QDateTime::addSecs()。

QTime QTime::currentTime () [静态]

返回当前时间,来自于系统时钟。

注意精确性取决于下面操作系统的精确性,不是所有的操作系统都有毫秒级精确度的。

实例:aclock/aclock.cpp、dclock/dclock.cpp、t12/cannon.cpp和tictac/tictac.cpp。

返回从最后一次调用start()或restart()到现在已经过去的毫秒数。

注意如果在最后一次调用start()或restart()后24小时,计数器转换为0。

注意精确性取决于下面操作系统的精确性,不是所有的操作系统都有毫秒级精确度的。

警告:如果最后一次调用start()或restart()之后,系统时钟设置发生了改变,结果将是不确定的。

也可以参考start()和restart()。

QTime QTime::fromString ( const QString& s, Qt::DateFormat f = Qt::TextDate ) [静态]通过给定的字符串s,使用格式f,返回这个QTime,或者如果这是不可能的话返回一个无效的时间。注意Qt::LocalDate在这里不能使用。

intQTime::hour () const

返回时间的小时部分(0-23)。

实例:tictac/tictac.cpp。

boolQTime::isNull () const

如果时间和00:00:00.000相等,返回真,否则返回假。零时间是有效的。

也可以参考isValid()。

boolQTime::isValid () const

如果时间是有效的,返回真,否则返回假。时间23:30:55.746是有效的,而24:12:30是无效的。

也可以参考isNull()。

bool QTime::isValid ( int h, int m, int s, int ms = 0 ) [静态]

这是一个重载成员函数,提供了方便。它的行为基本上和上面的函数相同。

如果时间是有效的,返回真,否则返回假。

如果h在0-23之间、m和s在0-59之间、ms在0-999之间,时间是有效的。

实例:

QTime::isValid(21, 10, 30); // 返回真

QTime::isValid(22, 5, 62); // 返回假

返回时间的分钟部分(0-59)。

实例:aclock/aclock.cpp和tictac/tictac.cpp。

intQTime::msec () const

返回时间的毫秒部分(0-999)。

intQTime::msecsTo ( const QTime& t ) const

返回这个时间到t的毫秒数(如果t早于这个时间,返回的为负数)。

因为QTime只能度量一天之内的时间,而且一天内只有86400000毫秒,所以结果就应该在-86400000毫秒和86400000毫秒之间。

也可以参考secsTo()。

boolQTime::operator!= ( const QTime& t ) const

如果这个时间不等于t,返回真,否则返回假。

boolQTime::operator< ( const QTime& t ) const

如果这个时间早于t,返回真,否则返回假。

boolQTime::operator<= ( const QTime& t ) const

如果这个时间不晚于t,返回真,否则返回假。

boolQTime::operator== ( const QTime& t ) const

如果这个时间等于t,返回真,否则返回假。

boolQTime::operator> ( const QTime& t ) const

如果这个时间晚于t,返回真,否则返回假。

boolQTime::operator>= ( const QTime& t ) const

如果这个时间不早于t,返回真,否则返回假。

intQTime::restart ()

设置这个时间为当前时间并且返回从最后一次调用start()或restart()到现在过去的毫秒数。

这个函数保证是原子的并且这样对于重复度量是非常方便的。调用start()开始第一次度量,然后调用restart()来做以后的每一次度量。

注意如果在最后一次调用start()或restart()后24小时,计数器转换为0。

警告:如果最后一次调用start()或restart()之后,系统时钟设置发生了改变,结果将是不确定的。

也可以参考start()、elapsed()和currentTime()。

intQTime::second () const

返回时间的秒部分(0-59)。

实例:tictac/tictac.cpp。

intQTime::secsTo ( const QTime& t ) const

返回这个时间到t的秒数(如果t早于这个时间,返回的为负数)。

因为QTime只能度量一天之内的时间,而且一天内只有86400秒,所以结果就应该在-86400秒和86400秒之间。

也可以参考addSecs() and QDateTime::secsTo().

实例:t12/cannon.cpp。

boolQTime::setHMS ( int h, int m, int s, int ms = 0 )

设置时间的时、分、秒和毫秒分别为h、m、s和ms。

h必须在0-23之间,m和s必须在0-59之间,ms必须在0-999之间。如果设置的时间有效,返回真,否则返回假。

也可以参考isValid()。

voidQTime::start ()

设置这个时间为当前时间。这是实际上使用来计时的:

QTime t;

t.start(); // 开始计时

... // 一些任务

qDebug( "%d\n", t.elapsed() ); // 打印过去的毫秒数

也可以参考restart()、elapsed()和currentTime()。

QString QTime::toString ( const QString& format ) const

返回一个字符串的时间。format参数决定了结果字符串的格式。

这些是可能用到的表达式:

?h - 没有前置0的数字的小时(0-23或者如果显示AM/PM时,1-12)

?hh - 前置0的数字的小时(00-23或者如果显示AM/PM时,01-12)

?m - 没有前置0的数字的分钟(0-59)

?mm - 前置0的数字的分钟(00-59)

?s - 没有前置0的数字的秒(0-59)

?ss - 前置0的数字的秒(00-59)

?z - 没有前置0的数字的毫秒(0-999)

?zzz - 前置0的数字的毫秒(000-999)

?AP - 切换为AM/PM显示。AP将被“AM”或“PM”替换。

?ap - 切换为am/pm显示。ap将被“am”或“pm”替换。

所有其他输入字符都将被忽略。

格式字符串实例(假设这个QTime为14:13:09.042)

?“hh:mm:ss.zzz”的结果将是“14:13:09.042”

?“h:m:s ap”的结果将是“2:13:9 pm”

也可以参考QDate::toString()和QTime::toString()。

QString QTime::toString ( Qt::DateFormat f = Qt::TextDate ) const

这是一个重载成员函数,提供了方便。它的行为基本上和上面的函数相同。

返回一个字符串的时间。f参数决定了结果字符串的格式。

如果f是Qt::TextDate,字符串格式是HH:MM:SS,比日午夜前一秒是“23:59:59”。

如果f是Qt::ISODate,字符串格式遵循ISO 8601表示时间的说明,也就是HH:MM:SS。

如果f是Qt::LocalDate,字符串格式依赖于系统的本地设置。

相关函数

QDataStream&operator<<( QDataStream& s, const QTime& t )

写时间t到流s中。

也可以参考QDataStream操作符的格式。

QDataStream&operator>>( QDataStream& s, QTime& t )

从流s中读取一个时间到t中。

也可以参考QDataStream操作符的格式。

QTimer,QTime的一点应用

分类:Qt2008-10-15 00:381114人阅读评论(0)收藏举报QTime可以及时流逝的时间

QTimer是“时机”;什么时间发生什么时候,发出一个SIGNAL,执行一个SLOT

例子1

#include

#include

#include

int main(int argc,char* argv[])

{

QApplication app(argc,argv);

std::vector list;

QTime tim;

tim.start();

for(int i=0; i<10; i++)

{

Sleep(100);

list.push_back(tim.elapsed() );

}

for(quint32 i=0; i

{

printf("%d ", list.at(i));

}

printf("/n");

return app.exec();

}

则输出为,109 203 312 406 516 609 703 812 906 1016

计算一下邻差94 109 94 110 93 94 109 94 110

差不多,基本维持在100毫秒的延时,这基本说明Sleep的精度,也说明QTime的用法之一。例子2:

----------------------timeout.h-----------

#include

class TIMEOUT:public QObject

{

Q_OBJECT

private:

QTime t;

public:

TIMEOUT()

{

t.start();

}

public slots:

void timeout()

{

qDebug("%d ", t.elapsed() );

}

};

---------------------main.cpp-------------

#include "timeout.h"

int main(int argc,char* argv[])

{

QApplication app(argc,argv);

std::vector list;

QTimer timer;

timer.start(100);

TIMEOUT out;

QObject::connect(&timer,SIGNAL(timeout()), &out, SLOT(timeout()));

for (int i=0; i<6;i++)

{

Sleep(50);

// qApp->processEvents();

}

return app.exec(); }

输出为

312

328

437

547

656

765

875

984

1094

1203

1312

1422

1531

1640

1750

1859

1969

2078

2187

2297

2406

2515

2625

2734

计算一下邻差,

16

109

110

109

109

110

109

110

109

109

110

109

109

110

109

110

109

109

110

109

可见执行Sleep的时候,QTimer是没有机会fire它的signal的;它眼巴巴的等着cpu有空了,才能释放signal;

那么是不是释放了signal,但是调度处理没有时机调用slot呢?也有可能吧,

但外在的表现是一直的,即来不及处理。

When a timer fires, the application sends a QTimerEvent, and the flow of control leaves the event loop until the timer event is processed. This implies that a timer cannot fire while your application is busy doing something else. In other words: the accuracy of timers depends on

the granularity of your application.

--------------Qt的assistant

上面的例子2中,如果反注释qApp->processEvents();

则输出为

156

250

328

438

547

656

766

875

985

1094

1203

1313

1422

1531

1641

1750

1860

1969

2078

2188

邻差为

109

109

110

109

110

109

109

110

109

109

110

109

110

109

109

110

可见这个qApp->processEvents()的作用了,见缝插针,只是第一个sleep和第二个sleep之间没有来得及插针。试图使用QTimer得到固定的,精确的,不依赖于当前任务的时延,是苦难的。

QTime Class Reference

The QTime class provides clock time functions. More...

#include

Note: All functions in this class are reentrant.

?List of all members, including inherited members

?Qt 3 support members

Public Functions

QTime ()

QTime ( int h, int m, int s = 0, int ms = 0 )

QTime addMSecs ( int ms ) const

QTime addSecs ( int s ) const

int elapsed () const

int hour () const

bool isNull () const

bool isValid () const

int minute () const

int msec () const

int msecsTo ( const QTime &t ) const

int restart ()

int second () const

int secsTo ( const QTime &t ) const

bool setHMS ( int h, int m, int s, int ms = 0 )

void start ()

QString toString ( const QString &format ) const

QString toString ( Qt::DateFormat format = Qt::TextDate ) const

bool operator!= ( const QTime &t ) const

bool operator< ( const QTime &t ) const

bool operator<= ( const QTime &t ) const

bool operator== ( const QTime &t ) const

bool operator> ( const QTime &t ) const

bool operator>= ( const QTime &t ) const

Static Public Members

QTime currentTime ()

QTime fromString ( const QString &string, Qt::DateFormat format = Qt::TextDate )

QTime fromString ( const QString &string, const QString &format )

bool isValid ( int h, int m, int s, int ms = 0 )

Related Non-Members

QDataStream &operator<< ( QDataStream &out, const QTime &time )

QDataStream &operator>> ( QDataStream &in, QTime &time )

Detailed Description

The QTime class provides clock time functions.

A QTime object contains a clock time, i.e. the number of hours, minutes, seconds, and milliseconds since midnight. It can read the current time from the system clock and measure a span of elapsed time. It provides functions for comparing times and for manipulating a time by adding a number of milliseconds.

QTime uses the 24-hour clock format; it has no concept of AM/PM. Unlike QDateTime, QTime knows nothing about time zones or daylight savings time (DST).

A QTime object is typically created either by giving the number of hours, minutes, seconds, and milliseconds explicitly, or by using the static function currentTime(), which creates a QTime object that contains the system's local time. Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

The hour(), minute(), second(), and msec() functions provide access to the number of hours, minutes, seconds, and milliseconds of the time. The same information is provided in textual format by the toString() function.

QTime provides a full set of operators to compare two QTime objects. One time is considered smaller than another if it is earlier than the other.

The time a given number of seconds or milliseconds later than a given time can be found using the addSecs() or addMSecs() functions. Correspondingly, the number of seconds or milliseconds between two times can be found using secsTo() or msecsTo().

QTime can be used to measure a span of elapsed time using the start(), restart(), and elapsed() functions.

See also QDate and QDateTime.

Member Function Documentation

QTime::QTime ()

Constructs a null time object. A null time can be a QTime(0, 0, 0, 0) (i.e., midnight) object, except that isNull() returns true and isValid() returns false.

See also isNull() and isValid().

QTime::QTime( int h, int m, int s = 0, int ms = 0 )

Constructs a time with hour h, minute m, seconds s and milliseconds ms.

h must be in the range 0 to 23, m and s must be in the range 0 to 59, and ms must be in the range 0 to 999.

See also isValid().

QTime QTime::addMSecs( int ms ) const

Returns a QTime object containing a time ms milliseconds later than the time of this object (or earlier if ms is negative).

Note that the time will wrap if it passes midnight. See addSecs() for an example.

See also addSecs(), msecsTo(), and QDateTime::addMSecs().

QTime QTime::addSecs( int s ) const

Returns a QTime object containing a time s seconds later than the time of this object (or earlier if s is negative).

Note that the time will wrap if it passes midnight.

Example:

QTime n(14,0,0); // n == 14:00:00

QTime t;

t =n.addSecs(70); // t == 14:01:10

t =n.addSecs(-70); // t == 13:58:50

t =n.addSecs(10*60*60+5); // t == 00:00:05

t =n.addSecs(-15*60*60); // t == 23:00:00

See also addMSecs(), secsTo(), and QDateTime::addSecs().

QTime QTime::currentTime () [static]

Returns the current time as reported by the system clock.

Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

int QTime::elapsed () const

Returns the number of milliseconds that have elapsed since the last time start() or restart() was called.

Note that the counter wraps to zero 24 hours after the last call to start() or restart.

Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

Warning: If the system's clock setting has been changed since the last time start() or restart() was called, the result is undefined. This can happen when daylight savings time is turned on or off.

See also start() and restart().

QTime QTime::fromString( const QString&string, Qt::DateFormat format =

Qt::TextDate ) [static]

Returns the time represented in the string as a QTime using the format given, or an invalid time if this is not possible.

Note that fromString() uses a "C" locale encoded string to convert milliseconds to a float value. If the default locale is not "C", this may result in two conversion attempts (if the conversion fails for the default locale). This should be considered an implementation detail.

QTime QTime::fromString( const QString&string, const QString&format ) [static]

Returns the QTime represented by the string, using the format given, or an invalid time if the string cannot be parsed.

These expressions may be used for the format:

Expression Output

h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)

hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)

m the minute without a leading zero (0 to 59)

mm the minute with a leading zero (00 to 59)

s the second without a leading zero (0 to 59)

ss the second with a leading zero (00 to 59)

z the milliseconds without leading zeroes (0 to 999)

zzz the milliseconds with leading zeroes (000 to 999)

AP interpret as an AM/PM time. AP must be either "AM" or "PM".

ap Interpret as an AM/PM time. ap must be either "am" or "pm".

All other input characters will be treated as text. Any sequence of characters that are enclosed in single quotes will also be treated as text and not be used as an expression.

QTime time =QTime::fromString("1mm12car00","m'mm'hcarss");

// time is 12:01.00

If the format is not satisfied an invalid QTime is returned. Expressions that do not expect leading zeroes to be given (h, m, s and z) are greedy. This means that they will use two digits even if this puts them outside the range of accepted values and leaves too few digits for other sections. For example, the following string could have meant 00:07:10, but the m will grab two digits, resulting in an invalid time:

QTime time =QTime::fromString("00:710","hh:ms"); // invalid

Any field that is not represented in the format will be set to zero. For example:

QTime time =QTime::fromString("1.30","m.s");

// time is 00:01:30.000

QDateTime::toString() QTime::toString()

See also QDateTime::fromString(), QDate::fromString(), and QDate::toString().

int QTime::hour () const

Returns the hour part (0 to 23) of the time.

See also minute(), second(), and msec().

bool QTime::isNull () const

Returns true if the time is null (i.e., the QTime object was constructed using the default constructor); otherwise returns false. A null time is also an invalid time.

See also isValid().

bool QTime::isValid () const

Returns true if the time is valid; otherwise returns false. For example, the time 23:30:55.746 is valid, but 24:12:30 is invalid.

See also isNull().

bool QTime::isValid ( int h, int m, int s, int ms = 0 ) [static]

This is an overloaded function.

Returns true if the specified time is valid; otherwise returns false.

The time is valid if h is in the range 0 to 23, m and s are in the range 0 to 59, and ms is in the range 0 to 999.

Example:

QTime::isValid(21,10,30); // returns true

QTime::isValid(22,5,62); // returns false

int QTime::minute () const

Returns the minute part (0 to 59) of the time.

See also hour(), second(), and msec().

int QTime::msec () const

Returns the millisecond part (0 to 999) of the time.

See also hour(), minute(), and second().

int QTime::msecsTo ( const QTime&t ) const

Returns the number of milliseconds from this time to t. If t is earlier than this time, the number of milliseconds returned is negative.

Because QTime measures time within a day and there are 86400 seconds in a day, the result is always between -86400000 and 86400000 ms.

See also secsTo(), addMSecs(), and QDateTime::msecsTo().

int QTime::restart ()

Sets this time to the current time and returns the number of milliseconds that have elapsed since the last time start() or restart() was called.

This function is guaranteed to be atomic and is thus very handy for repeated measurements. Call start() to start the first measurement, and restart() for each later measurement.

Note that the counter wraps to zero 24 hours after the last call to start() or restart().

Warning: If the system's clock setting has been changed since the last time start() or restart() was called, the result is undefined. This can happen when daylight savings time is turned on or off.

See also start(), elapsed(), and currentTime().

int QTime::second () const

Returns the second part (0 to 59) of the time.

See also hour(), minute(), and msec().

int QTime::secsTo ( const QTime&t ) const

Returns the number of seconds from this time to t. If t is earlier than this time, the number of seconds returned is negative.

Because QTime measures time within a day and there are 86400 seconds in a day, the result is always between -86400 and 86400.

secsTo() does not take into account any milliseconds.

See also addSecs() and QDateTime::secsTo().

回调函数

对于很多初学者来说,往往觉得回调函数很神秘,很想知道回调函数的工作原理。本文将要解释什么是回调函数、它们有什么好处、为什么要使用它们等等问题,在开始之前,假设你已经熟知了函数指针。 什么是回调函数? 简而言之,回调函数就是一个通过函数指针调用的函数。如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调函数。 为什么要使用回调函数? 因为可以把调用者与被调用者分开。调用者不关心谁是被调用者,所有它需知道的,只是存在一个具有某种特定原型、某些限制条件(如返回值为int)的被调用函数。 如果想知道回调函数在实际中有什么作用,先假设有这样一种情况,我们要编写一个库,它提供了某些排序算法的实现,如冒泡排序、快速排序、shell排序、shake排序等等,但为使库更加通用,不想在函数中嵌入排序逻辑,而让使用者来实现相应的逻辑;或者,想让库可用于多种数据类型(int、float、string),此时,该怎么办呢?可以使用函数指针,并进行回调。 回调可用于通知机制,例如,有时要在程序中设置一个计时器,每到一定时间,程序会得到相应的通知,但通知机制的实现者对我们的程序一无所知。而此时,就需有一个特定原型的函数指针,用这个指针来进行回调,来通知我们的程序事件已经发生。实际上,SetTimer() API使用了一个回调函数来通知计时器,而且,万一没有提供回调函数,它还会把一个消息发往程序的消息队列。 另一个使用回调机制的API函数是EnumWindow(),它枚举屏幕上所有的顶层窗口,为每个窗口调用一个程序提供的函数,并传递窗口的处理程序。如果被调用者返回一个值,就继续进行迭代,否则,退出。EnumWindow()并不关心被调用者在何处,也不关心被调用者用它传递的处理程序做了什么,它只关心返回值,因为基于返回值,它将继续执行或退出。 不管怎么说,回调函数是继续自C语言的,因而,在C++中,应只在与C代码建立接口,或与已有的回调接口打交道时,才使用回调函数。除了上述情况,在C++中应使用虚拟方法或函数符(functor),而不是回调函数。 一个简单的回调函数实现 下面创建了一个sort.dll的动态链接库,它导出了一个名为CompareFunction的类型--typedef int (__stdcall *CompareFunction)(const byte*, const byte*),它就是回调函数的类型。另外,它也导出了两个方法:Bubblesort()和Quicksort(),这两个方法原型相同,但实现了不同的排序算法。

在Excel中If函数的使用方法

在Excel中If函数的使用方法 ▲在“成绩表”工作表中,在“等级”字段下用粘贴函数的if 函数将“英语”成绩小于60分的用“不及格”表示;60~89分的用“合格”表示;大于等于90分的用“优秀”表示。 ▼=IF(E7>=90,"优秀",IF(AND(E7>=60,E7<90),"合格",IF(E7<60,"不及格"))) ■高中同学遇到了一个在excel中的函数问题,我们探讨了一下,感觉还可以,基本上可以实现目前想要的结果,就是在excel 中把两列的数值进行对应,输入一个值就出来另外一个数值.这样的问题可以用if函数来解决的,通过if函数自然就可以看到结果.不过这样的if最多就7个,不能满足需要,我觉得通过计算机其他语言的学习,我完全可以用case语句,如果case语句用不了,不知道还能用什么语句了. D2小于等于50,D3小于等于1800便为"合格"反之为:"不合格",公式应该是输入? =if(and(d2<=50,d3<=1800),"合格","不合格") 在B1单元格编辑公式 =IF(A1>=500,"一级",IF(AND(A1>=450,A1<500),"二级","三级")) 回车确认即可。 可以用填充柄把B1中的公式向下复制到相应的单元格。 就这些语句就足够了. 只要掌握了他的语句格式,和他的语法,基本上就可以解决的.不

过excel中应该还有很多其他的功能和算法需要研究. 眼镜小熊的问题:我在学校里做成绩单,老班要求每一个人列出自己的追赶目标是谁,为了在成绩单里体现每个同学的追赶成功与否,要把同学本人的成绩与被追赶同学的成绩加以比较,再返回Yes或No。可是用手工一个个向单元格里制造函数太累了,谁能帮我想个一劳永逸的办法? 增加K列,显示追赶成功与否的结果(如上图所示),在K4中输入公式: =IF(ISNA(MATCH(J4,$B$4:$B$9,0)),"",IF(H4

linux 的系统时间和硬件时间查看修改

linux 的系统时间有时跟硬件时间是不同步的 Linux时钟分为系统时钟(System Clock)和硬件(Real Time Clock,简称RTC)时钟。系统时钟是指当前Linux Kernel中的时钟,而硬件时钟则是主板上由电池供电的时钟,这个硬件时钟可以在BIOS中进行设置。当Linux启动时,硬件时钟会去读取系统时钟的设置,然后系统时钟就会独立于硬件运作。 Linux中的所有命令(包括函数)都是采用的系统时钟设置。在Linux中,用于时钟查看和设置的命令主要有date、hwclock和clock。其中,clock和hwclock用法相近,只用一个就行,只不过clock命令除了支持x86硬件体系外,还支持Alpha硬件体系。 1、date 查看系统时间 # date 设置系统时间 # date --set “07/07/06 10:19" (月/日/年时:分:秒) 2、hwclock/clock 查看硬件时间 # hwclock --show 或者# clock --show 设置硬件时间 # hwclock --set --date="07/07/06 10:19" (月/日/年时:分:秒) 或者# clock --set --date="07/07/06 10:19" (月/日/年时:分:秒) 3、硬件时间和系统时间的同步 按照前面的说法,重新启动系统,硬件时间会读取系统时间,实现同步,但是在不重新启动的时候,需要用hwclock或clock命令实现同步。 硬件时钟与系统时钟同步:# hwclock --hctosys(hc代表硬件时间,sys代表系统时间)或者# clock --hctosys 系统时钟和硬件时钟同步:# hwclock --systohc或者# clock --systohc

回调函数与回调机制

回调函数与回调机制 1. 什么是回调函数 回调函数(callback Function),顾名思义,用于回调的函数。回调函数只是一个功能片段,由用户按照回调函数调用约定来实现的一个函数。回调函数是一个工作流的一部分,由工作流来决定函数的调用(回调)时机。回调函数包含下面几个特性: ?属于工作流的一个部分; ?必须按照工作流指定的调用约定来申明(定义); ?他的调用时机由工作流决定,回调函数的实现者不能直接调用回调函数来实现工作流的功能; 2. 回调机制 回调机制是一种常见的设计模型,他把工作流内的某个功能,按照约定的接口暴露给外部使用者,为外部使用者提供数据,或要求外部使用者提供数据。 如上图所示,工作流提供了两个对外接口(获取参数、显示结果),以回调函数的形式实现。 ?“获取参数”回调函数,需要工作流使用者设定工作流计算需要的参数。 ?“显示结果”回调函数,提供计算结果给工作流使用者。

再以Windows的枚举顶级窗体为例。函数EnumWindows用于枚举当前系统中的所有顶级窗口,其函数原型为: BOOL EnumWindows( WNDENUMPROC lpEnumFunc, // callback function LPARAM lParam // application-defined value ); 其中lpEnumFunc是一个回调函数,他用于返回枚举过程中的获得的窗口的句柄。其定义约定为: BOOL CALLBACK EnumWindowsProc( HWND hwnd, // handle to parent window LPARAM lParam // application-defined value ); 在这个例子中,EnumWindows 是一个工作流,这个工作流用于遍历windows的所有窗口并获得其句柄。用户使用EnumWindows工作流的目的是想通过工作流来来获取窗口的句柄以便针对特定的一个或多个窗口进行相关处理。于是EnumWindows就扩展出接口lpEnumFunc,用于返回遍历的窗口句柄。 EnumWindows工作流的结束有两个方式:1,用户在回调函数中返回FALSE;2,再也找不到顶级窗口。我们可以推测EnumWindows的实现机制如下: 注:下列代码中的FindFirstTopWindows(), FindNextTopWindow()为假设的,Windows API 没有此函数,只是为了表明Enumwindows的内部流程。 BOOL EnumWindows( WNDENUMPROC lpEnumFunc, // callback function LPARAM lParam // application-defined value ) { BOOL bRet = TRUE; HWND hWnd = ::FindFirstTopWindows(); // 此函数是假设的,查找第一个顶级窗口 // 当hWnd为0时表示再也找不到顶级窗口 while( hWnd ) { bRet = (*lpEnumFunc)( hWnd, value ); if( !bRet) break; // 终止EnumWindows工作流; hWnd = ::FindNextWindow(); // 此函数是假设的,查找下一个顶级窗口 } } 在EnumWindows(...)函数中,实现了窗口枚举的工作流,他通过回调机制把用户关心(顶级窗口句柄)的和枚举工作流分开,用户不需要知道EnumWindows的具体实现,用户只要知道,设定了lpEnumFunc函数,然后把函数指针传给EnumWindwos就可以获得想要的窗口句柄。

hook的使用实例

在网上找了好久都没有找到消息hook的实例,下面是我的例子给大家分享一下 下面是dll中的代码: //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //我的经验,编译的时候会提示DllMain,已在DllMain.cpp中定义,把DllMain.cpp从源文件里删掉就好了 #include "stdafx.h" #include HHOOK hkey=NULL; HINSTANCE h_dll; #pragma data_seg(".MySec") //定义字段,段名.MySec HWND h_wnd=NULL; #pragma data_seg() #pragma comment(linker,"/section:.MySec,RWS") BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) { h_dll=hinstDLL; // MessageBox(0,"运行dllman","",MB_OK); return TRUE; } LRESULT CALLBACK my_test(int nCode,WPARAM wParam,LPARAM iParam)// { /* if(nCode==HC_ACTION) { MessageBox(0,"成功!!","标题",MB_OK); } else { MessageBox(0,"失败!!","标题",MB_OK); } */ MessageBox(0,"被截取","",MB_OK); UnhookWindowsHookEx(hkey); return 1; } void SetHook(HWND hwnd) { h_wnd = hwnd; // MessageBox(0,"运行sethook","",MB_OK); hkey=SetWindowsHookEx(WH_KEYBOARD,my_test,h_dll,0); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 下面是EXE的代码:有很多头文件是没用上的,我个人习惯都带着- -,虽然这不是好习惯

A设置系统的日期和时间

A设置系统的日期和时间 A设置系统的日期和时间2011-05-15 13:42间,以下_D__是正确的。 A.计算机内的时间是每次开机时,由AUTOEXEC.BAT向计算机输入的 B.开机时因为有外接电源,系统时间行走;关机后,则结束运行 C.计算机内的时光是每次开机时,系统依据当时情形,快乐女声,自动向计算机输入的 D.因为主机内装有高能电池,关机后系统时钟仍能行走 102为了畸形施展Windows3.2中文版的功能,则至少须要_A__的硬盘空间。 A.10MB B.20MB C.40MB D.80MB 103有些菜单项被选中后,还会显示出一 个方框来要求操作者进一步输入信息,这样的菜单项的右边有_C__。 A.√ B.▲ C.… D.暗色显示 104Windows借助于屏幕上的图形,向使用者提供了一种_D__操作环境。 A.命令 B.窗口 C.图形 D.窗口式多任务

105关于Windows3.2的以下说法,正确的是_C_。 A.必须脱离DOS独立运行 B.可以脱离DOS独破运行 C.必须依附DOS3.1以上版本的支撑才干工作 D.只有有80386以上的CPU就可以运行 106对于DOS的启动,除冷启动,热启动(Ctrl+Alt+Del)外,有的计算机还可以采取_C__来启动。 A.CTRL+RESET B.SHIFT+RESET C.RESET D.ALT+RESET 107在Windows中,有两类窗口:应用程序窗口和文档窗口__B_。 A.两者由运行一个应用程序的方式不同所翻开的 B.前者由运行一个应用程序打开,后者是要求显示或输入一些信息而在前者中打开 C.程序管理器窗口就是文档窗口,而程序组窗口就是应用程序窗口 D.前者是位于屏幕最前方的标题栏颜色异乎寻常的窗口 108Windows中,当屏幕上有多个窗口时,_D__是活动窗口。 A.可以有多个窗口 B.有一个固定的窗口 C.没有被其它窗口盖住的窗口 D.有一个标题栏的颜色不同凡响的窗口 109_D__代表当前目录中所有第二、第三字符为KL的文件名。 A.*KL*.*

IF函数的使用方法及操作实例

IF函数的使用方法及操作实例 分步阅读 IF函数:假设条件性的函数,即执行真假值的判断,根据逻辑计算的真假值,返回不同的结果。EXCEL中IF函数的使用非常广泛,特别是在单条件判断的时候,用好 IF函数可以帮我们完成很多功能。现结合具体的实例操作,进行说明:方法/步骤 1.一、IF函数的基本应用。 if(logical_test,value_if_true,value_if_false) IF是条件判断函数:=IF(测试条件,结果1,结果2),即如果满足“测试条件” 则显示“结果1”,如果不满足“测试条件”则显示“结果2”。 例一: 图1中,成绩结果60分以上(含60分)为及格,60分以下为不及格。执行IF 函数如下: 在C2单元格中输入:=IF(B2>=60,“及格”,“不及格”),再把此单元格格式往下拉动,即可。 注意:“及格”,“不及格”的双引号,要在英文输入法情况下输入的引号(" )。 如下图1。

2.二、IF函数的复杂应用。IF 函数条件带复合运算。 例二:股票佣金计算。在股票交易中,经常要考虑成本,而佣金占很大的成本。 佣金怎么计算?佣金:佣金费率最高千分之三,最低5元,不足5元,按5元收取。现在佣金费率以千分之三,运用IF函数进行计算。 图2中,红色单元格为佣金值。佣金 = 成交金额 * 佣金费率0.003 。在红色单元格D7中输入:=IF(D4*B7>=5,D4*B7,5) 就会自动计算佣金费。图 2.1为大于或等于5元时的情况,图2.2为不足5元时的情况,仍会显示5。 如下图2 3. 3 三、IF函数高级嵌套应用。

例三:IF函数嵌套运用。某公司销售提成的计算,销售额大于80万元(含80万),提成按40%计算;销售额为80-60万(含60万),提成按30%计算;销售额小于60万,提成按20%计算。计算方法:在C2单元格输入:=IF(B2>=800000,B2*0.4,IF(AND(B2<800000,B2>=600000),B2*0.3,IF(B2<600000,B2*0.2))) 如下图3。 END 注意事项 IF函数的嵌套,有几层IF条件,后面就有几个反括号。嵌套最多不要超过7层。

关于回调函数的几个例子(c)

以下是一个简单的例子。实现了一个repeat_three_times函数,可以把调用者传来的任何回调函数连续执行三次。 例 1. 回调函数 /* para_callback.h */ #ifndef PARA_CALLBACK_H #define PARA_CALLBACK_H typedef void (*callback_t)(void *); extern void repeat_three_times(callback_t, void *); #endif /* para_callback.c */ #include "para_callback.h" void repeat_three_times(callback_t f, void *para) { f(para); f(para); f(para); } /* main.c */ #include #include "para_callback.h" void say_hello(void *str) { printf("Hello %s\n", (const char *)str); } void count_numbers(void *num) { int i; for(i=1; i<=(int)num; i++) printf("%d ", i); putchar('\n');

} int main(void) { repeat_three_times(say_hello, "Guys"); repeat_three_times(count_numbers, (void *)4); return 0; } 回顾一下前面几节的例子,参数类型都是由实现者规定的。而本例中回调函数的参数按什么类型解释由调用者规定,对于实现者来说就是一个void *指针,实现者只负责将这个指针转交给回调函数,而不关心它到底指向什么数据类型。调用者知道自己传的参数是char *型的,那么在自己提供的回调函数中就应该知道参数要转换成char *型来解释。 回调函数的一个典型应用就是实现类似C++的泛型算法(Generics Algorithm)。下面实现的max函数可以在任意一组对象中找出最大值,可以是一组int、一组char或者一组结构体,但是实现者并不知道怎样去比较两个对象的大小,调用者需要提供一个做比较操作的回调函数。 例 2. 泛型算法 /* generics.h */ #ifndef GENERICS_H #define GENERICS_H typedef int (*cmp_t)(void *, void *); extern void *max(void *data[], int num, cmp_t cmp); #endif /* generics.c */ #include "generics.h" void *max(void *data[], int num, cmp_t cmp) { int i; void *temp = data[0];

OpenGL一个简单的例子

先编译运行一个简单的例子,这样我们可以有一个直观的印象。从这个例子我们可以看到OpenGL可以做什么,当然这个例子只做了很简单的一件事--绘制一个彩色的三角形。除此以外,我们还可以看到典型的OpenGL程序结构及openGL的运行顺序。 例1:本例在黑色的背景下绘制一个彩色的三角形,如图一所示。

图一:一个彩色的三角形首先创建工程,其步骤如下:

1)创建一个Win32 Console Application。 2)链接OpenGL libraries。在Visual C++中先单击Project,再单击Settings,再找到Link单击,最后在Object/library modules 的最前面加上OpenGL32.lib GLu32.lib GLaux.lib 3)单击Project Settings中的C/C++标签,将Preprocessor definitions 中的_CONSOLE改为__WINDOWS。最后单击OK。 现在你可以把下面的例子拷贝到工程中去,编译运行。你可以看到一个彩色的三角形。 我们先看看main函数。函数中以glut开头的函数都包含在glut.h中。GLUT库的函数主要执行如处理多窗口绘制、处理回调驱动事件、生成层叠式弹出菜单、绘制位图字体和笔画字体,以及各种窗口管理等任务。 ·glutInit用来初始化GLUT库并同窗口系统对话协商。 ·glutInitDisplayMode用来确定所创建窗口的显示模式。本例中的参数GLUT_SINGLE 指定单缓存窗口,这也是缺省模式,对应的模式为GLUT_DOUBLE 双缓存窗口。参数GLUT_RGB指定颜色RGBA模式,这也是缺省模式,对应的模式为GLUT_INDEX 颜色索引模式窗口。 ·glutInitWindowSize初始化窗口的大小,第一个参数为窗口的宽度,第二个参数为窗口的高度,以像素为单位。 ·glutInitWindowPosition设置初始窗口的位置,第一个参数为窗口左上角x的坐标,第二个参数为窗口左上角y的坐标,以像素为单位。屏幕的左上角的坐标为(0,0),横坐标向右逐渐增加,纵坐标向下逐渐增加。 ·glutCreateWindow创建顶层窗口,窗口的名字为扩号中的参数。 ·background() 这是自己写的函数,设置背景。其实这个函数中的语句可以写在display 函数中,但为了使功能块更加清晰,所以把背景这一部分单独提出来。 ·glutReshapeFunc注册当前窗口的形状变化回调函数。当改变窗口大小时,该窗口的形状改变回调函数将被调用。在此例中就是myReshape指定形状变化函数。 ·glutDisplayFunc注册当前窗口的显示回调函数。当一个窗口的图像层需要重新绘制时,GLUT将调用该窗口的的显示回调函数。在此例中的mydisplay就是显示回调函数,显示回调函数不带任何参数,它负责整个图像层的绘制。我们的大部分工作将集中在这个函数中。 ·glutMainLoop进入GLUT事件处理循环。glutMainLoop函数在GLUT程序中最多只能调用一次,它一旦被调用就不再返回,并且调用注册过的回调函数。所以这个函数必须放在注册回调函数的后面,此例中为glutReshapeFunc,glutDisplayFunc。

在Excel中If函数的使用方法

在Excel中If函数的使用方法 电脑资讯2007-10-15 16:58:46 阅读3614 评论0 字号:大中小订阅 ▲在“成绩表”工作表中,在“等级”字段下用粘贴函数的if函数将“英语”成绩小于60分的用“不及格”表示;60~89分的用“合格”表示;大于等于90分的用“优秀”表示。 ▼=IF(E7>=90,"优秀",IF(AND(E7>=60,E7<90),"合格",IF(E7<60,"不及格"))) ■高中同学遇到了一个在excel中的函数问题,我们探讨了一下,感觉还可以,基本上可以实现目前想要的结果,就是在excel中把两列的数值进行对应,输入一个值就出来另外一个数值.这样的问题可以用if函数来解决的,通过if函数自然就可以看到结果.不过这样的if最多就7个,不能满足需要,我觉得通过计算机其他语言的学习,我完全可以用case语句,如果case语句用不了,不知道还能用什么语句了. D2小于等于50,D3小于等于1800便为"合格"反之为:"不合格",公式应该是输入? =if(and(d2<=50,d3<=1800),"合格","不合格") 在B1单元格编辑公式 =IF(A1>=500,"一级",IF(AND(A1>=450,A1<500),"二级","三级")) 回车确认即可。 可以用填充柄把B1中的公式向下复制到相应的单元格。 就这些语句就足够了. 只要掌握了他的语句格式,和他的语法,基本上就可以解决的.不过excel中应该还有很多其他的功能和 算法需要研究. □在Excel中If函数的使用方法https://www.360docs.net/doc/277644880.html,/question/15517131.html https://www.360docs.net/doc/277644880.html,/qdike/blog/item/6f639f58c48be7de9c8204cb.html 回答眼镜小熊的问题:我在学校里做成绩单,老班要求每一个人列出自己的追赶目标是谁,为了在成绩单里体现每个同学的追赶成功与否,要把同学本人的成绩与被追赶同学的成绩加以比较,再返回Yes 或No。可是用手工一个个向单元格里制造函数太累了,谁能帮我想个一劳永逸的办法? 增加K列,显示追赶成功与否的结果(如上图所示),在K4中输入公式: =IF(ISNA(MATCH(J4,$B$4:$B$9,0)),"",IF(H4

Matlab的GUI回调函数

Kinds of Callbacks The following table lists the callback properties that are available, their triggering events, and the components to which they apply. Note:User interface controls include push buttons, sliders, radio buttons, check boxes, editable text boxes, static text boxes, list boxes, and toggle buttons. They are sometimes referred to as uicontrols.

GUIDE Callback Arguments All callbacks in a GUIDE-generated GUI code file have the following standard input arguments: hObject —Handle of the object, e.g., the GUI component, for which the callback was triggered. For a button group SelectionChangeFcn callback, hObject is the handle of the selected radio button or toggle button. eventdata — Sequences of events triggered by user actions such as table selections emitted by a component in the form of a MATLAB struct (or an empty matrix for components that do not generate eventdata) handles — A MATLAB struct that contains the handles of all the objects in the GUI, and may also contain application-defined data. See handles Structure for information about this structure. Object Handle The first argument is the handle of the component issuing the callback. Use it to obtain relevant properties that the callback code uses and change them as necessary. For example, theText = get(hObject,'String'); places the String property (which might be the contents of static text or name of a button) into the local variable theText. You can change the property by setting it, for example set(hObject,'String',date) This particular code changes the text of the object to display the current date. Event Data Event data is a stream of data describing user gestures, such as key presses, scroll wheel movements, and mouse drags. The auto-generated callbacks of GUIDE GUIs can access event data for Handle Graphics? and uicontrol and uitable object callbacks. The following ones receive event data when triggered: CellEditCallback in a uitable CellSelectionCallback in a uitable KeyPressFcn in uicontrols and figures KeyReleaseFcn in a figure SelectionChangeFcn in a uibuttongroup WindowKeyPressFcn in a figure or any of its child objects WindowKeyReleaseFcn in a figure or any of its child objects WindowScrollWheelFcn in a figure Event data is passed to GUIDE-generated callbacks as the second of three standard arguments. For components that issue no event data the argument is empty. For those that provide event data, the argument contains a structure, which varies in composition according to the component that generates it and the type of event. For example, the event data for a key-press provides information on the key(s) currently being pressed. Here is a GUIDE-generated KeyPressFcn callback template: % --- Executes on key press with focus on checkbox1 and none of its controls. function checkbox1_KeyPressFcn(hObject, eventdata, handles)

时间管理系统时间设置办法

最新卓越管理方案您可自由编辑

DVR 系统时钟设置方法 当DVR不能启动出现以下画面的时候需要重新设置系统时钟,操作步骤如下: 1.DVR与PC的连接使用串口交叉线。(注意:串口交叉线是2-3 ,3-2 ,5-5脚相连接) 2.硬件连接: 将PC后面板上的串口和DVR后面板上的RS-232相连; 3.设置时间前请记下机箱外壳标签上的ETHERNET ADD(MAC地址),比如(00:00:F0:54:44:18) 4.运行电脑系统中的“超级终端”软件,进行连接设置。如下图: RS-232 串口 SHR-4080 背板PC 背板 NETWORK NETWORK

任意输入一个名称和任意选择一个图标,按“确定”键。 国家、区号、电话号码不用设置,在“连接时使用”选择“COM 1或COM 2”(根据实际的连接情况进行选择)

设置COM口属性: 1)每秒位数(波特率):115200 2)数据位、机偶校验、停止位的参数不用修改 3)数据流控制选择“无” 点击’确定’键,进入到等待连接状态。 然后拔掉DVR的电源,等1分钟后再重新接上电源,超级终端会出现以下画面:

5.超级终端会自动进入到时间设置,请按提示输入“年、月、日、时、分、秒”。如下图:

6.接着进入到DVR网络地址设置,可以选择“1.Auto”或“2.Manual” 6.出现以下画面的时候根据你设置的DVR的型号选择,如下图你设置的是SHR-4081P则选择1,是SHR-4160则按其它键后回车或直接回车。如果“HOST Name”只有一个型号选择时只需要直接回车便可。

WH_CBT回调函数

CBTProc Callback Function An application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function before activating, creating, destroying, minimizing, maximizing, moving, or sizing a window; before completing a system command; before removing a mouse or keyboard event from the system message queue; before setting the keyboard focus; or before synchronizing with the system message queue. A computer-based training (CBT) application uses this hook procedure to receive useful notifications from the system. The HOOKPROC type defines a pointer to this callback function. CBTProc is a placeholder for the application-defined or library-defined function name. Syntax 复制 LRESULT CALLBACK CBTProc( __in int nCode, __in WPARAM wParam, __in LPARAM lParam ); Parameters nCode [in] Type: int The code that the hook procedure uses to determine how to process the message. If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. This parameter can be one of the following values.

linux+系统时间设置方法

Linux 系统时间设置 #include #include #include #include #include unsigned char SetTime(uint8 *timess) { struct timeval *settvv=malloc( sizeof( struct timeval ) ); time_t curdate; struct tm *tdate=malloc( sizeof( struct tm ) ); unsigned char f=0; tdate->tm_year=timess[0]+2000-1900; //年 tdate->tm_mon=timess[1]-1; // 月 tdate->tm_mday=timess[2]; // 日 tdate->tm_wday=timess[6]; // 星期 tdate->tm_hour=timess[3]; // 小时 tdate->tm_min=timess[4]; // 分钟 tdate->tm_sec=timess[5]; // 秒钟 curdate=mktime(tdate); settvv->tv_sec=curdate; settvv->tv_usec=0; if( settimeofday ( settvv, (struct timezone *)0 )<0 ) { printf("settime error:%s\n\a",strerror(errno)); f=1; } system("hwclock –systohc");//系统时钟和硬件时钟同步:(让系统的时间同步到硬件时钟) free(tdate); free(settvv); return f; }

回调函数的概念及其使用

回调函数的概念及其使用

回调函数的概念及其使用 1 什么是回调 软件模块之间总是存在着一定的接口,从调用方式上,可以把他们分为三类:同步调用、回调和异步调用。同步调用是一种阻塞式调用,调用方要等待对方执行完毕才返回,它是一种单向调用;回调是一种双向调用模式,也就是说,被调用方在接口被调用时也会调用对方的接口;异步调用是一种类似消息或事件的机制,不过它的调用方向刚好相反,接口的服务在收到某种讯息或发生某种事件时,会主动通知客户方(即调用客户方的接口)。回调和异步调用的关系非常紧密,通常我们使用回调来实现异步消息的注册,通过异步调用来实现消息的通知。同步调用是三者当中最简单的,而回调又常常是异步调用的基础,因此,下面我们着重讨论回调机制在不同软件架构中的实现。 对于不同类型的语言(如结构化语言和对象语言)、平台(Win32、JDK)或构架(CORBA、DCOM、WebService),客户和服务的交互除了同步方式以外,都需要具备一定的异步通知机制,让服务方(或接口提供方)在某些情况下能够主动通知客户,而回调是实现异步的一个最简捷的途径。 对于一般的结构化语言,可以通过回调函数来实现回调。回调函数也是一个函数或过程,不过它是一个由调用方自己实现,供被调用方使用的特殊函数。

在面向对象的语言中,回调则是通过接口或抽象类来实现的,我们把实现这种接口的类成为回调类,回调类的对象成为回调对象。对于象C++或Object Pascal 这些兼容了过程特性的对象语言,不仅提供了回调对象、回调方法等特性,也能兼容过程语言的回调函数机制。 Windows平台的消息机制也可以看作是回调的一种应用,我们通过系统提供的接口注册消息处理函数(即回调函数),从而实现接收、处理消息的目的。由于Windows平台的API是用C语言来构建的,我们可以认为它也是回调函数的一个特例。 对于分布式组件代理体系CORBA,异步处理有多种方式,如回调、事件服务、通知服务等。事件服务和通知服务是CORBA用来处理异步消息的标准服务,他们主要负责消息的处理、派发、维护等工作。对一些简单的异步处理过程,我们可以通过回调机制来实现。 下面我们集中比较具有代表性的语言(C、Object Pascal)和架构(CORBA)来分析回调的实现方式、具体作用等。 2 过程语言中的回调(C) 2.1 函数指针 回调在C语言中是通过函数指针来实现的,通过将回调函数的地址传给被调函数从而实现回调。因此,要实现回调,必须首先定义函数指针,请看下面的例子: void Func(char *s);// 函数原型 void (*pFunc) (char *);//函数指针 可以看出,函数的定义和函数指针的定义非常类似。 一般的化,为了简化函数指针类型的变量定义,提高程序的可读性,我们需要把函数指针类型自定义一下。 typedef void(*pcb)(char *); 回调函数可以象普通函数一样被程序调用,但是只有它被当作参数传递给被调函数时才能称作回调函数。 被调函数的例子:

相关文档
最新文档