QT中怎么读写ini配置文件
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章主要介绍"QT中怎么读写ini配置文件",在日常操作中,相信很多人在QT中怎么读写ini配置文件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"QT中怎么读写in
千家信息网最后更新 2026年11月01日QT中怎么读写ini配置文件
这篇文章主要介绍"QT中怎么读写ini配置文件",在日常操作中,相信很多人在QT中怎么读写ini配置文件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"QT中怎么读写ini配置文件"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
如图1所示,我们需要在QT界面中实现手动读取参数存放的位置,那么我们该如何做呢?
方法:读取ini格式的配置文件,实现路径的写入与读取。
第一步:界面构造函数中,初始化一个Config.ini文件
//初始化一个.ini配置文件 //qApp是QT系统自带的,可以直接使用QString iniFilePath=qApp->applicationDirPath()+"/Config.ini";//如果不存在Config.ini,便生成一个Config.ini。如果已经存在了,则略过。if(!QFile::exists(iniFilePath)){ QSettings configIniWrite(iniFilePath,QSettings::IniFormat); configIniWrite.beginGroup("calib_data_path"); configIniWrite.setValue("calib_data_path","FA0180090134.xml"); configIniWrite.endGroup(); configIniWrite.beginGroup("robot_pose_file"); configIniWrite.setValue("robot_pose_file_path","robot_pose_file.txt"); configIniWrite.endGroup();}第二步:定义一个保存Config文件的函数
void saveConfig(const QString& group,const QString& name, const QVariant& var){ QString iniFilePath = qApp->applicationDirPath() + "/Config.ini"; if (QFile::exists(iniFilePath)) { QSettings configIniWrite(iniFilePath,QSettings::IniFormat); configIniWrite.beginGroup(group); configIniWrite.setValue(name,var); configIniWrite.endGroup(); }}第三步:设置路径
Demo1:
//设置相机标定文件路径void CalibrationForm::btnLoadCamParaPath_clicked(){ QFileDialog dialog(this,tr("Select calib data file")); dialog.setAcceptMode(QFileDialog::AcceptOpen); dialog.setFileMode(QFileDialog::ExistingFile); static bool firstDialog = true; if (firstDialog) { firstDialog = false; const QStringList fileLocations = QStandardPaths::standardLocations(QStandardPaths::DesktopLocation); dialog.setDirectory(fileLocations.isEmpty() ? QDir::currentPath():fileLocations.last()); } dialog.setNameFilter(tr("FA0180090134(*.xml)")); if (dialog.exec()==QDialog::Accepted) { //获得文件夹路径+文件名 _campara_path = dialog.selectedFiles().first(); ui->lineEditCamParaPath->setText(_campara_path); //此处是在lineEdit窗口显示路径名+文件名 saveConfig("calib_data_path","calib_data_path",_campara_path); }}demo2:
//设置手眼标定时的机械臂运动轨迹路径void CalibrationForm::btnLoadRobotPara_clicked(){ QFileDialog dialog(this,tr("Select robot pose file")); dialog.setAcceptMode(QFileDialog::AcceptOpen); dialog.setFileMode(QFileDialog::ExistingFile); static bool first_Dialog = true; if (first_Dialog) { first_Dialog = false; const QStringList fileLocations = QStandardPaths::standardLocations(QStandardPaths::DesktopLocation); dialog.setDirectory(fileLocations.isEmpty()?QDir::currentPath():fileLocations.last()); } dialog.setNameFilter(tr("robot_pose_file(*.txt)")); if (dialog.exec()==QDialog::Accepted) { _robot_pose_path = dialog.selectedFiles().first(); ui->lineEditRobotPath->setText(_robot_pose_path); saveConfig("robot_pose_file","robot_pose_file_path",_robot_pose_path); }}由于ini文件不可在星球中上传,此处用txt形式的截图作为附件,见图2.
到此,关于"QT中怎么读写ini配置文件"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
文件
配置
路径
学习
函数
文件名
方法
更多
界面
帮助
实用
接下来
位置
参数
形式
截图
手动
手眼
文件夹
文章
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技名片
盈实互联网科技
互联网 科技
互联网科技的发展
以房互联网科技
北京禾田雨橡互联网科技
四个字互联网科技公司取名
中正互联网科技招聘
阿里巴巴算科技企业还是互联网
金融科技与互联网金融相同和不同
互联网校园科技培训
互联网5g黑科技有哪些
西安小鹰速贷互联网科技有限公司
明优互联网科技有限公司
互联网金融科技元年
科技互联网行业投资研究
美国五大互联网科技公司市值多少
科技互联网专业工作会议发言稿
互联网科技大佬云集
宁波允成互联网科技有限公司
碳银互联网科技有限公司
互联网 科技馆
新华互联网科技2019
赶超互联网科技 微信多开
移动互联网科技公司
互联网媒体平台算高科技产业
上海创道互联网络科技有限公司
互联网科技手抄报图片
美国五大互联网科技公司市值多少
互联网科技博主张洲