1.VS2019+Qt获取电脑设备名称
(1)添加网络模块network
VS2019 Qt 怎么添加Qt模块?_vs 2019 qt widget应用程序泵设置 qt module_令狐掌门的博客-CSDN博客
(2)关键代码:
#include <QHostInfo>
QString hostname=QHostInfo::localHostName();
qDebug() << hostname;
2.QSettings学习
QT学习之如何读写配置文件(QSettings) (zhihu.com)
关键代码1:
#include <QSettings>
QSettings* settings = new QSettings("setting.ini", QSettings::IniFormat);
settings->beginGroup("MAIN");
settings->setValue("CSDN_TITLE", "QingXun");
settings->endGroup();
settings->beginGroup("OTHER");
settings->setValue("CSDN_DESCRIPTION", "Share My Learning exprience");
settings->endGroup();
这段代码可以在目录中生成(写入)setting.ini文件。
结构:
[group]
key=value
关键代码2:
先创建setting.ini文件
读取.ini文件。
QSettings* settings = new QSettings("setting1.ini", QSettings::IniFormat);
settings->beginGroup("QT");
QString LEARN_OBJECT = settings->value("LEARN_OBJECT", "").toString();
double VERSION = settings->value("QT_VERSION", -1).toDouble();
qDebug() << "LEARN_OBJECT=" << LEARN_OBJECT << endl;
qDebug() << "QT_VERSION=" << VERSION << endl;
settings->endGroup();
读写注册表
QSettings 读写注册表_qsettings读取注册表_leyou2018的博客-CSDN博客
我这个完全是模仿ta的文章,有效
写
// 公司名称
QCoreApplication::setOrganizationName(QString("lianlianlian"));
// App 名称
QCoreApplication::setApplicationName(QString("helper"));
QSettings settings(QSettings::NativeFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
// 写入键值对
settings.setValue("Name", "Qt Creator");
settings.setValue("Version", 5);
读
QString strName = settings.value("Name").toString();
int nVersion = settings.value("Version").toInt();
qDebug() << strName;
qDebug() << nVersion;