这几天在上嵌入式课程设计,需要用到Qt,这个是信号与槽的,寒假的时候也简单学习了一些,但是没有怎么深入,又回过来看了看Qt,发现Qt的ui界面配置与Android的好像,当然Qt也可以拿来开发Android。
void testRegexCapture()
{
QString pattern(“(.*)=(.*)”);
QRegExp rx(pattern);
QString str(“a=100″);
int pos = str.indexOf(rx); // 0, position of the first match.
// Returns -1 if str is not found.
// You can also use rx.indexIn(str);
qDebug() << pos;
if ( pos >= 0 )
{
qDebug() << rx.matchedLength(); // 5, length of the last matched string
// or -1 if there was no match
qDebug() << rx.capturedTexts(); // QStringList(“a=100″, ”a”, ”100″),
// 0: text matching pattern
// 1: text captured by the 1st ()
// 2: text captured by the 2nd ()
qDebug() << rx.cap(0); // a=100, text matching pattern
qDebug() << rx.cap(1); // a, text captured by the nth ()
qDebug() << rx.cap(2); // 100,
qDebug() << rx.pos(0); // 0, position of the nth captured text
qDebug() << rx.pos(1); // 0
qDebug() << rx.pos(2); // 2
}
}
QString s = ”a=100″;
s.replace(QRegExp(“(.*)=”), ”b=”);
qDebug() << s; // b=100
QString s = ”a=100″;
s.replace(QRegExp(“(.*)=(.*)”), ”\\1\\2=\\2″); // \1 is rx.cap(1), \2 is rx.cap(2)
qDebug() << s; // a100=100
void testRegexMatch()
{
QString pattern(“.*=.*”);
QRegExp rx(pattern);
bool match = rx.exactMatch(“a=3″);
qDebug() << match; // True
match = rx.exactMatch(“a/2″);
qDebug() << match; // False
}