我有以下函数,它应该使用正则表达式检查文本文件的日期,然后我在检查函数下面有我的gui类的插槽,它应该将check函数找到的所有日期附加到QTextEdit。由于某种原因,即使我在包含几个日期的文本文件上运行检查功能,也没有任何内容被附加到QTextEdit。知道我做错了吗?
代码:
QStringList RegExChecker::check(QStringList textToCheck) {
QRegExp dayInText("\\d{1, 2]\\W");
QRegExp monthInText("\\d{1, 2}|\\.\\.\\.*\\W");
QRegExp yearInText("19\\d\\d|20\\d\\d");
QStringList datesFound;
for (int i = 1; i <= textToCheck.size(); ++i) {
for (int j = i + 1; j <= textToCheck.size(); ++j) {
for (int k = j + 1; k <= textToCheck.size(); ++k) {
if ((dayInText.exactMatch(textToCheck.at(i)) || yearInText.exactMatch(textToCheck.at(i)))
&& monthInText.exactMatch(textToCheck.at(j))
&& (yearInText.exactMatch(textToCheck.at(k)) || dayInText.exactMatch(textToCheck.at(k)))) {
datesFound.append(QString("%1 %2 %3").arg(textToCheck.at(i)).arg(textToCheck.at(j)).arg(textToCheck.at(k)));
}
}
}
}
return datesFound;
}
void MainWindow::checkText() {
RegExChecker rc;
QStringList dates = rc.check(text);
foreach (QString str, dates)
ui->txtContents->append(str);
}