//ini文件数据读取到Tab Widget控件中
QFileInfo iniFileInfo = QFileInfo(iniPathString); //iniPathString为ini文件的路径
if(iniFileInfo.exists()) //如果ini文件存在
{
QSettings *config = new QSettings(iniPathString, QSettings::IniFormat);
config->setIniCodec(QTextCodec::codecForName("utf-8"));//设置ini文件为utf-8格式
for(int i = 0; i < 10; i++)//假设最大十个section
{
QString section = QString("teacher%1/").arg(i);//格式化
if(config->value(section + "name").toString().isEmpty())
{
continue;//空数据不做处理
}
currentRow = i; //当前行数
ui->tableWidget->insertRow(i);//插入新行
itemName = config->value(section + "name").toString();
currentColumn = 0;
ui->tableWidget->setItem(currentRow, currentColumn, new QTableWidgetItem(itemName));//插入第0行第0列
itemName = config->value(section + "course").toString();
currentColumn = 1;
ui->tableWidget->setItem(currentRow, currentColumn, new QTableWidgetItem(itemName));//插入0行第1列
itemName = config->value(section + "time").toString();
currentColumn = 2;
ui->tableWidget->setItem(currentRow, currentColumn, new QTableWidgetItem(itemName));//插入第0行第2列
itemName = config->value(section + "read").toString();
currentColumn = 3;
ui->tableWidget->setItem(currentRow, currentColumn, new QTableWidgetItem(itemName));//插入第0行第3列
}
delete config;
}