QFile file("/home/wj/file_table/test.txt");
QString py;
QString chn;
QString content;
QRegExp regExp("([^A-Za-z]*)([*]{0,1}[A-Za-z]*)"); //split拼音和汉字的正则化表达式
if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
{
qDebug()<<"open file error";
return 0;
}
else
{
QTextStream text_stream(&file);
while(!file.atEnd())
{
content=text_stream.readLine(0);
content.trimmed();
if(regExp.indexIn(content)>-1)
{
py=regExp.cap(2);
chn=regExp.cap(1);
qDebug()<<py;
qDebug()<<chn;
query.exec("insert into pingyin values('"+py+"','"+chn+"')"); //将拼音和汉字存入数据表pingying
}
}
}
file.close();
qDebug 只显示第一行记录