{"id":977,"date":"2013-12-29T13:02:51","date_gmt":"2013-12-29T05:02:51","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=977"},"modified":"2013-12-29T13:02:51","modified_gmt":"2013-12-29T05:02:51","slug":"qt%e8%af%bb%e5%86%99ini%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=977","title":{"rendered":"Qt\u8bfb\u5199ini\u6587\u4ef6"},"content":{"rendered":"<p>\u672c\u6587\u8f6c\u8f7d\u81ea\uff1a<a href=\"http:\/\/blog.csdn.net\/qiurisuixiang\/article\/details\/7760828\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/blog.csdn.net\/qiurisuixiang\/article\/details\/7760828<\/a><\/p>\n<h2>\u4e00\u00a0\u80cc\u666f<\/h2>\n<p>&nbsp;<\/p>\n<h3><a name=\"t1\"><\/a>1\u00a0ini\u6587\u4ef6\u4ecb\u7ecd<\/h3>\n<p>.ini\u00a0\u6587\u4ef6\u662fInitialization\u00a0File\u7684\u7f29\u5199\uff0c\u5373\u521d\u59cb\u5316\u6587\u4ef6\u3002<br \/>\n\u9664\u4e86windows\u73b0\u5728\u5f88\u591a\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u4e0b\u9762\u7684\u5e94\u7528\u8f6f\u4ef6\u4e5f\u6709.ini\u6587\u4ef6\uff0c\u7528\u6765\u914d\u7f6e\u5e94\u7528\u8f6f\u4ef6\u4ee5\u5b9e\u73b0\u4e0d\u540c\u7528\u6237\u7684\u8981\u6c42\u3002\u4e00\u822c\u4e0d\u7528\u76f4\u63a5\u7f16\u8f91\u8fd9\u4e9b.ini\u6587\u4ef6\uff0c\u5e94\u7528\u7a0b\u5e8f\u7684\u56fe\u5f62\u754c\u9762\u5373\u53ef\u64cd\u4f5c\u4ee5\u5b9e\u73b0\u76f8\u540c\u7684\u529f\u80fd\u3002\u5b83\u53ef\u4ee5\u7528\u6765\u5b58\u653e\u8f6f\u4ef6\u4fe1\u606f,\u6ce8\u518c\u8868\u4fe1\u606f\u7b49\u3002<br \/>\n&nbsp;<\/p>\n<h3><a name=\"t2\"><\/a>2\u00a0ini\u6587\u4ef6\u683c\u5f0f<\/h3>\n<p>INI\u6587\u4ef6\u7531\u8282\u3001\u952e\u3001\u503c\u7ec4\u6210\u3002<br \/>\n\u8282<br \/>\n[section]<br \/>\n\u53c2\u6570\uff08\u952e=\u503c\uff09<br \/>\nname=value<br \/>\n&nbsp;<br \/>\n\u4e0b\u9762\u662f\u4e00\u4e2aini\u6587\u4ef6\u7684\u4f8b\u5b50<\/p>\n<pre>\n[Section1 Name] \u3000\u3000\nKeyName1=value1 \u3000\u3000\nKeyName2=value2 \u3000\u3000\n... \u3000\u3000\n[Section2 Name] \u3000\u3000\nKeyName21=value21 \u3000\u3000\nKeyName22=value22 \u3000\n<\/pre>\n<p>\u5176\u4e2d\uff1a[Section1\u00a0Name]\u7528\u6765\u8868\u793a\u4e00\u4e2a\u6bb5\u843d\u3002\u56e0\u4e3aINI\u6587\u4ef6\u53ef\u80fd\u662f\u9879\u76ee\u4e2d\u5171\u7528\u7684\uff0c\u6240\u4ee5\u4f7f\u7528[Section\u00a0Name]\u6bb5\u540d\u6765\u533a\u5206\u4e0d\u540c\u7528\u9014\u7684\u53c2\u6570\u533a\u3002\u4f8b\u5982\uff1a[Section1\u00a0Name]\u8868\u793a\u4f20\u611f\u5668\u7075\u654f\u5ea6\u53c2\u6570\u533a\uff1b[Section2\u00a0Name]\u8868\u793a\u6d4b\u91cf\u901a\u9053\u53c2\u6570\u533a\u7b49\u7b49\u3002<br \/>\n\u6ce8\u89e3\uff1a\u4f7f\u7528\u5206\u53f7\u8868\u793a\uff08;\uff09\u3002\u5728\u5206\u53f7\u540e\u9762\u7684\u6587\u5b57\uff0c\u76f4\u5230\u8be5\u884c\u7ed3\u5c3e\u90fd\u5168\u90e8\u4e3a\u6ce8\u89e3\u3002<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<h2><a name=\"t3\"><\/a>\u4e8c\u00a0Qt\u5199ini\u6587\u4ef6<\/h2>\n<div><b>\u00a0<\/b><\/div>\n<pre lang=\"c++\">\n#include <qtCore\/QCoreApplication>\n#include <qsettings>\nint main(int argc, char *argv[])\n{\n   QCoreApplication a(argc, argv);\n   \/\/Qt\u4e2d\u4f7f\u7528QSettings\u7c7b\u8bfb\u5199ini\u6587\u4ef6\n   \/\/QSettings\u6784\u9020\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662fini\u6587\u4ef6\u7684\u8def\u5f84,\u7b2c\u4e8c\u4e2a\u53c2\u6570\u8868\u793a\u9488\u5bf9ini\u6587\u4ef6,\u7b2c\u4e09\u4e2a\u53c2\u6570\u53ef\u4ee5\u7f3a\u7701\n   QSettings *configIniWrite = new QSettings(\"hahaya.ini\", QSettings::IniFormat);\n   \/\/\u5411ini\u6587\u4ef6\u4e2d\u5199\u5165\u5185\u5bb9,setValue\u51fd\u6570\u7684\u4e24\u4e2a\u53c2\u6570\u662f\u952e\u503c\u5bf9\n   \/\/\u5411ini\u6587\u4ef6\u7684\u7b2c\u4e00\u4e2a\u8282\u5199\u5165\u5185\u5bb9,ip\u8282\u4e0b\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\n   configIniWrite->setValue(\"\/ip\/first\", \"192.168.0.1\");\n   \/\/\u5411ini\u6587\u4ef6\u7684\u7b2c\u4e00\u4e2a\u8282\u5199\u5165\u5185\u5bb9,ip\u8282\u4e0b\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\n   configIniWrite->setValue(\"ip\/second\", \"127.0.0.1\");\n   \/\/\u5411ini\u6587\u4ef6\u7684\u7b2c\u4e8c\u4e2a\u8282\u5199\u5165\u5185\u5bb9,port\u8282\u4e0b\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\n   configIniWrite->setValue(\"port\/open\", \"2222\");\n   \/\/\u5199\u5165\u5b8c\u6210\u540e\u5220\u9664\u6307\u9488\n   delete configIniWrite;\n   return a.exec();\n}\n<\/pre>\n<p>\u8fd0\u884c\u7a0b\u5e8f\u540e\uff0c\u6253\u5f00\u7a0b\u5e8f\u76ee\u5f55\u4e0b\u7684hahaya.ini\u6587\u4ef6\uff0c\u7ed3\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<br \/>\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/my.csdn.net\/uploads\/201207\/18\/1342617390_9257.png\" \/><br \/>\n&nbsp;<\/p>\n<h2><a name=\"t4\"><\/a>\u4e09\u00a0Qt\u8bfbini\u6587\u4ef6<\/h2>\n<div><\/div>\n<pre lang=\"c++\">\n#include <qtCore\/QCoreApplication>\n#include <qsettings>\nint main(int argc, char *argv[])\n{\n   QCoreApplication a(argc, argv);\n   \/\/Qt\u4e2d\u4f7f\u7528QSettings\u7c7b\u8bfb\u5199ini\u6587\u4ef6\n   \/\/QSettings\u6784\u9020\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662fini\u6587\u4ef6\u7684\u8def\u5f84,\u7b2c\u4e8c\u4e2a\u53c2\u6570\u8868\u793a\u9488\u5bf9ini\u6587\u4ef6,\u7b2c\u4e09\u4e2a\u53c2\u6570\u53ef\u4ee5\u7f3a\u7701\n   QSettings *configIniWrite = new QSettings(\"hahaya.ini\", QSettings::IniFormat);\n   \/\/\u5411ini\u6587\u4ef6\u4e2d\u5199\u5165\u5185\u5bb9,setValue\u51fd\u6570\u7684\u4e24\u4e2a\u53c2\u6570\u662f\u952e\u503c\u5bf9\n   \/\/\u5411ini\u6587\u4ef6\u7684\u7b2c\u4e00\u4e2a\u8282\u5199\u5165\u5185\u5bb9,ip\u8282\u4e0b\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\n   configIniWrite->setValue(\"\/ip\/first\", \"192.168.0.1\");\n   \/\/\u5411ini\u6587\u4ef6\u7684\u7b2c\u4e00\u4e2a\u8282\u5199\u5165\u5185\u5bb9,ip\u8282\u4e0b\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\n   configIniWrite->setValue(\"ip\/second\", \"127.0.0.1\");\n   \/\/\u5411ini\u6587\u4ef6\u7684\u7b2c\u4e8c\u4e2a\u8282\u5199\u5165\u5185\u5bb9,port\u8282\u4e0b\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\n   configIniWrite->setValue(\"port\/open\", \"2222\");\n   \/\/\u5199\u5165\u5b8c\u6210\u540e\u5220\u9664\u6307\u9488\n   delete configIniWrite;\n   return a.exec();\n}\n<\/pre>\n<p>\u7a0b\u5e8f\u8fd0\u884c\u622a\u56fe\uff1a<br \/>\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/my.csdn.net\/uploads\/201207\/18\/1342617465_4837.png\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u8f6c\u8f7d\u81ea\uff1ahttp:\/\/blog.csdn.net\/qiurisuixiang\/article\/details\/7760828 \u4e00\u00a0\u80cc\u666f &nbsp; 1\u00a0ini\u6587\u4ef6\u4ecb\u7ecd .ini\u00a0\u6587\u4ef6\u662fInitialization\u00a0File\u7684\u7f29\u5199\uff0c\u5373\u521d\u59cb\u5316\u6587\u4ef6\u3002 \u9664\u4e86windows\u73b0\u5728\u5f88\u591a\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u4e0b\u9762\u7684\u5e94\u7528\u8f6f\u4ef6\u4e5f\u6709.ini\u6587\u4ef6\uff0c\u7528\u6765\u914d\u7f6e\u5e94\u7528\u8f6f\u4ef6\u4ee5\u5b9e\u73b0\u4e0d\u540c\u7528\u6237\u7684\u8981\u6c42\u3002\u4e00\u822c\u4e0d\u7528\u76f4\u63a5\u7f16\u8f91\u8fd9\u4e9b.ini\u6587\u4ef6\uff0c\u5e94\u7528\u7a0b\u5e8f\u7684\u56fe\u5f62\u754c\u9762\u5373\u53ef\u64cd\u4f5c\u4ee5\u5b9e\u73b0\u76f8\u540c\u7684\u529f\u80fd\u3002\u5b83\u53ef\u4ee5\u7528\u6765\u5b58\u653e\u8f6f\u4ef6\u4fe1\u606f,\u6ce8\u518c\u8868\u4fe1\u606f\u7b49\u3002 &nbsp; 2\u00a0ini\u6587\u4ef6\u683c\u5f0f INI\u6587\u4ef6\u7531\u8282\u3001\u952e\u3001\u503c\u7ec4\u6210\u3002 \u8282 [section] \u53c2\u6570\uff08\u952e=\u503c\uff09 name=value &nbsp; \u4e0b\u9762\u662f\u4e00\u4e2aini\u6587\u4ef6\u7684\u4f8b\u5b50 [Section1 Name] \u3000\u3000 KeyName1=value1 \u3000\u3000 KeyName2=value2 \u3000\u3000 &#8230; \u3000\u3000 [Section2 Name] \u3000\u3000 KeyName21=value21 \u3000\u3000 KeyName22=value22 \u3000 \u5176\u4e2d\uff1a[Section1\u00a0Name]\u7528\u6765\u8868\u793a\u4e00\u4e2a\u6bb5\u843d\u3002\u56e0\u4e3aINI\u6587\u4ef6\u53ef\u80fd\u662f\u9879\u76ee\u4e2d\u5171\u7528\u7684\uff0c\u6240\u4ee5\u4f7f\u7528[Section\u00a0Name]\u6bb5\u540d\u6765\u533a\u5206\u4e0d\u540c\u7528\u9014\u7684\u53c2\u6570\u533a\u3002\u4f8b\u5982\uff1a[Section1\u00a0Name]\u8868\u793a\u4f20\u611f\u5668\u7075\u654f\u5ea6\u53c2\u6570\u533a\uff1b[Section2\u00a0Name]\u8868\u793a\u6d4b\u91cf\u901a\u9053\u53c2\u6570\u533a\u7b49\u7b49\u3002 \u6ce8\u89e3\uff1a\u4f7f\u7528\u5206\u53f7\u8868\u793a\uff08;\uff09\u3002\u5728\u5206\u53f7\u540e\u9762\u7684\u6587\u5b57\uff0c\u76f4\u5230\u8be5\u884c\u7ed3\u5c3e\u90fd\u5168\u90e8\u4e3a\u6ce8\u89e3\u3002 &nbsp; &nbsp; \u4e8c\u00a0Qt\u5199ini\u6587\u4ef6 \u00a0 #include #include int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); \/\/Qt\u4e2d\u4f7f\u7528QSettings\u7c7b\u8bfb\u5199ini\u6587\u4ef6 \/\/QSettings\u6784\u9020\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662fini\u6587\u4ef6\u7684\u8def\u5f84,\u7b2c\u4e8c\u4e2a\u53c2\u6570\u8868\u793a\u9488\u5bf9ini\u6587\u4ef6,\u7b2c\u4e09\u4e2a\u53c2\u6570\u53ef\u4ee5\u7f3a\u7701 QSettings *configIniWrite = new QSettings(&#8220;hahaya.ini&#8221;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[90],"class_list":["post-977","post","type-post","status-publish","format-standard","hentry","category-study","tag-qt"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=977"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/977\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}