QT编程中对于文件操作的程序讲解,最好是把下面的程序一句一句的解释下:在线等,十分感谢
答案:1 悬赏:60
解决时间 2021-03-02 01:00
- 提问者网友:浪荡绅士
- 2021-03-01 17:02
QT编程中对于文件操作的程序讲解,最好是把下面的程序一句一句的解释下:在线等,十分感谢
最佳答案
- 二级知识专家网友:青灯有味
- 2021-03-01 18:13
void funlibEdit::InitTypeData()
{
//读基本类型
QFile file("datatype"); //datatype为读取的文件名,这里可以为路径,否则表示为当前路径
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))//设置为Text方式只读,并判断是否打开
return;//若打开失败直接返回
QTextStream in(&file); //将内容读到文本流中,即in中为datatype中的所有内容
while (!in.atEnd()) //循环遍历到结束
{
QString loctype = in.readLine(); //读一行到locttupe
loctype = loctype.simplified();//这个应该是化简,具体我不清楚,你可以去看下手册simplified的函数功能
m_typelist.append(loctype);//在m_typelist这段字符串之后加上loctype这个字符串
}
file.close();//关闭打开的datatype文件
//读类型映射
QFile mapfile("datatypemap");
if (!mapfile.open(QIODevice::ReadOnly | QIODevice::Text))//同上判断
return;
QTextStream mapin(&mapfile); //同上
while (!mapin.atEnd())//同上
{
QString mapline = mapin.readLine(); //同上
int index = mapline.indexOf(":"); //所以“:”,返回位置
QString outtype = mapline.left(index).simplified(); //同上
QString intype= mapline.right(mapline.length()-index-1).simplified();//同上
m_typemap[outtype] = intype;//放到数组中,功能同上
}
mapfile.close();//同上
}
{
//读基本类型
QFile file("datatype"); //datatype为读取的文件名,这里可以为路径,否则表示为当前路径
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))//设置为Text方式只读,并判断是否打开
return;//若打开失败直接返回
QTextStream in(&file); //将内容读到文本流中,即in中为datatype中的所有内容
while (!in.atEnd()) //循环遍历到结束
{
QString loctype = in.readLine(); //读一行到locttupe
loctype = loctype.simplified();//这个应该是化简,具体我不清楚,你可以去看下手册simplified的函数功能
m_typelist.append(loctype);//在m_typelist这段字符串之后加上loctype这个字符串
}
file.close();//关闭打开的datatype文件
//读类型映射
QFile mapfile("datatypemap");
if (!mapfile.open(QIODevice::ReadOnly | QIODevice::Text))//同上判断
return;
QTextStream mapin(&mapfile); //同上
while (!mapin.atEnd())//同上
{
QString mapline = mapin.readLine(); //同上
int index = mapline.indexOf(":"); //所以“:”,返回位置
QString outtype = mapline.left(index).simplified(); //同上
QString intype= mapline.right(mapline.length()-index-1).simplified();//同上
m_typemap[outtype] = intype;//放到数组中,功能同上
}
mapfile.close();//同上
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯