17,086
社区成员
发帖
与我相关
我的任务
分享
void QtConnectMysql::UseTableModify(QSqlDatabase db,QString table,FindKey &FindWords,LPCSTR upath1,LPCSTR spath2)
{
QTextCodec *code = QTextCodec::codecForName("utf8");
QString Qstr = " ";
QString upath = upath1;
QSqlTableModel qTable(0,db);
qTable.setTable(table);
qTable.setFilter("topic_id>0");
qTable.select();
int num = qTable.rowCount();
for(int i=0;i<num;i++)
{
QSqlRecord record = qTable.record(i);
//QFile sfile(upath1);
QFile sfile(upath);
if(!sfile.open(QIODevice::WriteOnly |QIODevice::Text))
{
qDebug()<<"Open file failed\n";
return ;
}
QTextStream sout(&sfile);
sout.setCodec(code);
Qstr = record.value("text").toString();
sout<<Qstr<<endl;
FindWords.SingleSeparateWords(upath1,spath2);
map<string,int> MapStr;
int nResult;
FindWords.ClearWords(spath2,MapStr);
//this is the first method to get the result
/*nResult = FindWords.SingleResult1(MapStr);*/
//this is the second method to get the result
nResult = FindWords.SingleResult2(MapStr);
record.setValue("kind",nResult);
qTable.setRecord(i,record);
}
if(qTable.submitAll())
{
std::cout<<"修改成功"<<endl;
//return true;
}
else
{
std::cout<<"修改不成功"<<endl;
//return false;
}
}