{"id":44,"date":"2024-08-20T10:42:18","date_gmt":"2024-08-20T02:42:18","guid":{"rendered":"https:\/\/cnsn.rr.nu\/?p=44"},"modified":"2024-08-20T10:42:18","modified_gmt":"2024-08-20T02:42:18","slug":"qt%e4%b8%ad%e7%a8%8b%e5%ba%8f%e9%85%8d%e7%bd%ae%e4%b8%8e%e6%97%a5%e5%bf%97%e8%af%a5%e5%a6%82%e4%bd%95%e4%bf%9d%e5%ad%98","status":"publish","type":"post","link":"https:\/\/blog.cnsn.fun\/?p=44","title":{"rendered":"qt\u4e2d\u7a0b\u5e8f\u914d\u7f6e\u4e0e\u65e5\u5fd7\u8be5\u5982\u4f55\u4fdd\u5b58"},"content":{"rendered":"<h3>1. <strong>\u4f7f\u7528\u7b80\u5355\u6587\u4ef6\u5b58\u50a8<\/strong><\/h3>\n<p>\u5bf9\u4e8e\u5185\u5b58\u5360\u7528\u7684\u6700\u5c0f\u5316\uff0c\u6700\u76f4\u63a5\u7684\u65b9\u5f0f\u662f\u4f7f\u7528\u7b80\u5355\u7684\u6587\u4ef6\u5b58\u50a8\u800c\u975e\u6570\u636e\u5e93\u3002\u4f60\u53ef\u4ee5\u5c06\u914d\u7f6e\u548c\u65e5\u5fd7\u6570\u636e\u5206\u522b\u4fdd\u5b58\u5230\u666e\u901a\u6587\u4ef6\u4e2d\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u914d\u7f6e\u6570\u636e<\/strong>\uff1a\u4f7f\u7528JSON\u3001INI\u3001XML\u7b49\u683c\u5f0f\u6765\u5b58\u50a8\u914d\u7f6e\u6570\u636e\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7Qt\u7684<code>QSettings<\/code>\u6216\u624b\u52a8\u8bfb\u53d6\/\u5199\u5165\u6587\u4ef6\u6765\u7ba1\u7406\u8fd9\u4e9b\u6570\u636e\u3002<code>QSettings<\/code>\u5728Windows\u4e0a\u4f1a\u9ed8\u8ba4\u4f7f\u7528\u6ce8\u518c\u8868\u6765\u5b58\u50a8\u914d\u7f6e\uff0c\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4f1a\u5360\u7528\u592a\u591a\u5185\u5b58\uff0c\u4e14\u8bfb\u53d6\u901f\u5ea6\u5feb\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u65e5\u5fd7\u6570\u636e<\/strong>\uff1a\u53ef\u4ee5\u7b80\u5355\u5730\u5c06\u65e5\u5fd7\u6570\u636e\u5199\u5165\u5230\u6587\u672c\u6587\u4ef6\u4e2d\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u4f7f\u7528\u540c\u6b65\u6216\u5f02\u6b65\u5199\u5165\u3002\u5bf9\u4e8e\u5b9e\u65f6\u65e5\u5fd7\u8bb0\u5f55\uff0c\u76f4\u63a5\u8ffd\u52a0\u5230\u6587\u4ef6\u672b\u5c3e\u662f\u6700\u8282\u7701\u5185\u5b58\u7684\u65b9\u5f0f\u3002Qt\u63d0\u4f9b\u4e86<code>QFile<\/code>\u7c7b\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u64cd\u4f5c\u6587\u4ef6\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u51e0\u4e4e\u4e0d\u4f1a\u589e\u52a0\u5185\u5b58\u5360\u7528\uff0c\u9664\u4e86\u6587\u4ef6I\/O\u64cd\u4f5c\u672c\u8eab\u7684\u5c11\u91cf\u5f00\u9500\u3002<\/p>\n<h3>2. <strong>\u8003\u8651\u4f7f\u7528\u5185\u5b58\u6620\u5c04\u6587\u4ef6\uff08Memory-mapped File\uff09<\/strong><\/h3>\n<p>\u5982\u679c\u4f60\u4ecd\u7136\u5e0c\u671b\u4f7f\u7528\u6570\u636e\u5e93\u6587\u4ef6\u6765\u7ba1\u7406\u6570\u636e\uff0c\u4f46\u5e0c\u671b\u6700\u5c0f\u5316\u5185\u5b58\u4f7f\u7528\uff0c\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u53ef\u80fd\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002SQLite\u652f\u6301\u5c06\u6570\u636e\u5e93\u6587\u4ef6\u6620\u5c04\u5230\u5185\u5b58\u4e2d\uff0c\u51cf\u5c11\u5185\u5b58\u4e2d\u7684\u6570\u636e\u590d\u5236\u548c\u7f13\u5b58\u5f00\u9500\u3002<\/p>\n<ul>\n<li><strong>\u4f18\u70b9<\/strong>\uff1a\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u5141\u8bb8\u4f60\u76f4\u63a5\u5728\u5185\u5b58\u4e2d\u64cd\u4f5c\u6587\u4ef6\u5185\u5bb9\uff0c\u4e0d\u9700\u8981\u5c06\u6574\u4e2a\u6587\u4ef6\u8bfb\u5165\u5185\u5b58\uff0c\u8282\u7701\u4e86\u5185\u5b58\u5360\u7528\u3002<\/li>\n<li><strong>\u6ce8\u610f<\/strong>\uff1a\u4f7f\u7528\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u9700\u8981\u6ce8\u610f\u6587\u4ef6\u5927\u5c0f\u548c\u64cd\u4f5c\u7cfb\u7edf\u9650\u5236\uff0c\u4f46\u5728\u5904\u7406\u8f83\u5c0f\u89c4\u6a21\u7684\u6570\u636e\u65f6\uff0c\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u6709\u6548\u964d\u4f4e\u5185\u5b58\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<h3>3. <strong>\u8f7b\u91cf\u7ea7\u65e5\u5fd7\u8bb0\u5f55<\/strong><\/h3>\n<p>\u5982\u679c\u65e5\u5fd7\u8bb0\u5f55\u7684\u91cf\u4e0d\u5927\uff0c\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u5185\u5b58\u5360\u7528\u6781\u4f4e\u7684\u8f7b\u91cf\u7ea7\u65e5\u5fd7\u8bb0\u5f55\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li><strong>\u76f4\u63a5\u5199\u5165\u6587\u4ef6<\/strong>\uff1a\u4f7f\u7528Qt\u7684<code>QFile<\/code>\u76f4\u63a5\u5c06\u65e5\u5fd7\u5185\u5bb9\u5199\u5165\u6587\u4ef6\uff0c\u907f\u514d\u5728\u5185\u5b58\u4e2d\u7f13\u5b58\u8fc7\u591a\u65e5\u5fd7\u6570\u636e\u3002<\/li>\n<li><strong>\u4f7f\u7528\u6700\u5c0f\u5316\u683c\u5f0f<\/strong>\uff1a\u5728\u4fdd\u5b58\u65e5\u5fd7\u65f6\uff0c\u907f\u514d\u4f7f\u7528\u590d\u6742\u7684\u65e5\u5fd7\u683c\u5f0f\uff0c\u9009\u62e9\u7b80\u5355\u7684\u7eaf\u6587\u672c\u6216CSV\u683c\u5f0f\uff0c\u4ee5\u51cf\u5c11\u5904\u7406\u548c\u5b58\u50a8\u5f00\u9500\u3002<\/li>\n<\/ul>\n<h3>4. <strong>\u51cf\u5c11SQLite3\u7f13\u5b58<\/strong><\/h3>\n<p>\u5982\u679c\u4f60\u51b3\u5b9a\u7ee7\u7eed\u4f7f\u7528SQLite3\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u914d\u7f6e\u6765\u6700\u5c0f\u5316\u5176\u5185\u5b58\u4f7f\u7528\uff1a<\/p>\n<ul>\n<li><strong>\u51cf\u5c11\u9875\u9762\u7f13\u5b58<\/strong>\uff1a\u901a\u8fc7<code>PRAGMA cache_size<\/code>\u547d\u4ee4\u8c03\u6574SQLite\u7684\u9875\u9762\u7f13\u5b58\u5927\u5c0f\u3002\u4f8b\u5982\uff0c\u5c06\u7f13\u5b58\u5927\u5c0f\u8bbe\u7f6e\u4e3a\u8f83\u5c0f\u503c\uff08\u5982\u9ed8\u8ba4\u503c\u76841\/4\u6216\u66f4\u5c0f\uff09\uff0c\u53ef\u4ee5\u51cf\u5c11SQLite\u7684\u5185\u5b58\u5360\u7528\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">PRAGMA cache_size = -200;  -- \u5c06\u7f13\u5b58\u5927\u5c0f\u8bbe\u7f6e\u4e3a200KB<\/code><\/pre>\n<ul>\n<li><strong>\u5173\u95ed\u4e0d\u5fc5\u8981\u7684\u529f\u80fd<\/strong>\uff1a\u53ef\u4ee5\u5173\u95edSQLite\u4e2d\u7684\u4e00\u4e9b\u4e0d\u5fc5\u8981\u7684\u529f\u80fd\u6765\u51cf\u5c11\u5185\u5b58\u4f7f\u7528\uff0c\u5982\u5173\u95ed<code>journal_mode<\/code>\u6216\u8bbe\u7f6e<code>PRAGMA synchronous<\/code>\u4e3a<code>OFF<\/code>\uff0c\u4ece\u800c\u51cf\u5c11\u5185\u5b58\u548c\u78c1\u76d8\u64cd\u4f5c\u5f00\u9500\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">PRAGMA journal_mode = OFF;\nPRAGMA synchronous = OFF;<\/code><\/pre>\n<h3>5. <strong>\u4f7f\u7528\u5185\u5b58\u6570\u636e\u5e93<\/strong><\/h3>\n<p>\u5982\u679c\u914d\u7f6e\u548c\u65e5\u5fd7\u6570\u636e\u53ea\u662f\u77ed\u671f\u5b58\u5728\uff0c\u5e76\u4e14\u4e0d\u9700\u8981\u5728\u7a0b\u5e8f\u5173\u95ed\u540e\u4fdd\u5b58\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5185\u5b58\u6570\u636e\u5e93\uff1a<\/p>\n<ul>\n<li><strong>SQLite\u5185\u5b58\u6570\u636e\u5e93<\/strong>\uff1a\u4f7f\u7528SQLite\u65f6\uff0c\u53ef\u4ee5\u5c06\u6570\u636e\u5e93\u5b8c\u5168\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff08\u4f7f\u7528<code>:memory:<\/code>\uff09\uff0c\u4ece\u800c\u907f\u514d\u78c1\u76d8I\/O\u548c\u5927\u90e8\u5206\u5185\u5b58\u5f00\u9500\u3002\u4e0d\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e\u6570\u636e\u4e0d\u9700\u8981\u6301\u4e45\u5316\u7684\u573a\u666f\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">QSqlDatabase db = QSqlDatabase::addDatabase(&quot;QSQLITE&quot;);\ndb.setDatabaseName(&quot;:memory:&quot;);<\/code><\/pre>\n<ul>\n<li><strong>\u5185\u5b58\u7ed3\u6784\u7ba1\u7406<\/strong>\uff1a\u4f7f\u7528Qt\u7684\u5bb9\u5668\u7c7b\u5982<code>QMap<\/code>\u3001<code>QHash<\/code>\u7b49\u6765\u7ba1\u7406\u914d\u7f6e\u548c\u65e5\u5fd7\u6570\u636e\uff0c\u4fdd\u6301\u6570\u636e\u5728\u5185\u5b58\u4e2d\u5904\u7406\uff0c\u5e76\u5b9a\u671f\u540c\u6b65\u5230\u6587\u4ef6\u6216\u78c1\u76d8\u3002<\/li>\n<\/ul>\n<h3>6. <strong>\u5b9a\u671f\u6e05\u7406\u548c\u538b\u7f29\u6570\u636e<\/strong><\/h3>\n<p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u5b58\u50a8\u65b9\u5f0f\uff0c\u5b9a\u671f\u6e05\u7406\u548c\u538b\u7f29\u6570\u636e\u90fd\u80fd\u5e2e\u52a9\u51cf\u5c11\u5185\u5b58\u548c\u78c1\u76d8\u5360\u7528\uff1a<\/p>\n<ul>\n<li><strong>\u65e5\u5fd7\u6e05\u7406<\/strong>\uff1a\u5b9a\u671f\u6e05\u7406\u8001\u65e7\u65e5\u5fd7\uff0c\u6216\u8005\u5728\u8fbe\u5230\u4e00\u5b9a\u6570\u91cf\u6216\u5927\u5c0f\u65f6\u81ea\u52a8\u5f52\u6863\u548c\u5220\u9664\u65e7\u65e5\u5fd7\u3002<\/li>\n<li><strong>\u6570\u636e\u5e93\u6e05\u7406<\/strong>\uff1a\u5982\u679c\u4f7f\u7528SQLite\uff0c\u53ef\u4ee5\u5b9a\u671f\u8fd0\u884c<code>VACUUM<\/code>\u547d\u4ee4\uff0c\u538b\u7f29\u6570\u636e\u5e93\u6587\u4ef6\uff0c\u51cf\u5c11\u6587\u4ef6\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">VACUUM;<\/code><\/pre>\n<h3>7. <strong>\u5229\u7528Windows\u7684\u7279\u6b8a\u529f\u80fd<\/strong><\/h3>\n<p>Windows\u63d0\u4f9b\u4e86\u4e00\u4e9b\u72ec\u7279\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u51cf\u5c11\u5185\u5b58\u5360\u7528\u7684\u540c\u65f6\uff0c\u4fdd\u6301\u6027\u80fd\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u6587\u4ef6\u538b\u7f29<\/strong>\uff1aWindows\u652f\u6301NTFS\u538b\u7f29\u529f\u80fd\u3002\u4f60\u53ef\u4ee5\u5c06\u5b58\u50a8\u65e5\u5fd7\u548c\u914d\u7f6e\u7684\u6587\u4ef6\u5939\u8bbe\u7f6e\u4e3a\u538b\u7f29\u72b6\u6001\uff0c\u8282\u7701\u78c1\u76d8\u7a7a\u95f4\uff0c\u540c\u65f6\u5bf9\u5185\u5b58\u5360\u7528\u5f71\u54cd\u8f83\u5c0f\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u8282\u7701\u5185\u5b58\u7684\u64cd\u4f5c<\/strong>\uff1a\u4f7f\u7528Windows\u7279\u5b9a\u7684API\u8fdb\u884c\u5185\u5b58\u7ba1\u7406\uff0c\u4f8b\u5982\u63a7\u5236\u7a0b\u5e8f\u5185\u5b58\u5206\u9875\uff0c\u51cf\u5c11\u672a\u4f7f\u7528\u6570\u636e\u7684\u5185\u5b58\u9a7b\u7559\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u7ed3\u8bba<\/h3>\n<p>\u4e3a\u4e86\u5c3d\u91cf\u51cf\u5c11\u5185\u5b58\u5360\u7528\uff0c\u5efa\u8bae\u5728\u4f60\u7684\u573a\u666f\u4e2d\u9009\u62e9\u7b80\u5355\u7684\u6587\u4ef6\u5b58\u50a8\uff08\u5982JSON\u3001INI\u6587\u4ef6\u7528\u4e8e\u914d\u7f6e\uff0c\u65e5\u5fd7\u6587\u4ef6\u7528\u4e8e\u65e5\u5fd7\u8bb0\u5f55\uff09\uff0c\u5e76\u901a\u8fc7Qt\u7684\u6587\u4ef6I\/O\u7c7b\u8fdb\u884c\u64cd\u4f5c\u3002\u5982\u679c\u4f60\u4ecd\u7136\u9700\u8981\u4f7f\u7528\u6570\u636e\u5e93\u529f\u80fd\uff0c\u53ef\u4ee5\u901a\u8fc7\u51cf\u5c11SQLite\u7684\u7f13\u5b58\u548c\u529f\u80fd\u8bbe\u7f6e\u6765\u964d\u4f4e\u5185\u5b58\u5f00\u9500\u3002<\/p>\n<p>\u6700\u7ec8\u7684\u9009\u62e9\u5e94\u57fa\u4e8e\u5177\u4f53\u7684\u9879\u76ee\u9700\u6c42\u3002\u5982\u679c\u9879\u76ee\u5bf9\u6301\u4e45\u6027\u3001\u6570\u636e\u7ed3\u6784\u5316\u7ba1\u7406\u6709\u8f83\u9ad8\u8981\u6c42\uff0c\u90a3\u4e48\u4f7f\u7528SQLite3\u4ecd\u7136\u662f\u5408\u7406\u7684\u9009\u62e9\uff0c\u4f46\u4f60\u53ef\u4ee5\u901a\u8fc7\u4f18\u5316\u914d\u7f6e\u5c06\u5185\u5b58\u5360\u7528\u63a7\u5236\u5728\u6700\u5c0f\u8303\u56f4\u5185\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u4f7f\u7528\u7b80\u5355\u6587\u4ef6\u5b58\u50a8 \u5bf9\u4e8e\u5185\u5b58\u5360\u7528\u7684\u6700\u5c0f\u5316\uff0c\u6700\u76f4\u63a5\u7684\u65b9\u5f0f\u662f\u4f7f\u7528\u7b80\u5355\u7684\u6587\u4ef6\u5b58\u50a8\u800c\u975e\u6570\u636e\u5e93\u3002\u4f60\u53ef\u4ee5\u5c06\u914d\u7f6e\u548c\u65e5\u5fd7\u6570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[13,22,30,33],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-qt","tag-c","tag-qt","tag-30","tag-33"],"_links":{"self":[{"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=44"}],"version-history":[{"count":0,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}