int QString::compare ( const QString & s ) const
这是一个重载成员函数,提供了方便。它的行为基本上和上面的函数相同。
对这个字符串和s进行词典比较,如果它小于、等于或者大于s,就返回小于、等于或者大于0的整数。
QFile file("abc.txt");QString string="abc";char a='a';QString check;if(!file.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::warning(this,tr("错误提示"),tr("打开文件失败!"),QMessageBox::Ok);
return 0;
}check=file.readAll();//一、查找是否有括号里的字符或字符串,如果有,返回1,如果无,返回0check.contains(string); 如果要忽略大小写,带参数:check.contains(string,Qt::CaseInsensitive);//二、查找是否有括号里的字符或字符串,如果有,返回当前位置(如例,返回0),如果无,返回-1,注意位置是从0开始的check.indexOf(string);//都可以带很多参数file.close();
建议看下字符编码,看看是否一致