Linux下QT读取ini文件
时间: 2023-07-18 07:14:05 浏览: 114
在 Linux 下使用 QT 读取 ini 文件,可以使用 QT 提供的 QSettings 类来实现。以下是一个简单的例子:
```c++
#include <QCoreApplication>
#include <QDebug>
#include <QSettings>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// 创建 QSettings 对象,指定 ini 文件路径和格式
QSettings settings("/path/to/ini/file.ini", QSettings::IniFormat);
// 读取 key 为 "username" 的值
QString username = settings.value("username").toString();
qDebug() << "Username:" << username;
// 读取 key 为 "password" 的值
QString password = settings.value("password").toString();
qDebug() << "Password:" << password;
return a.exec();
}
```
在这个例子中,我们创建了一个 QSettings 对象来读取 ini 文件中的数据。你只需要指定 ini 文件的路径和格式,然后通过 `value()` 方法读取指定 key 的值即可。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)