{"id":366,"date":"2024-07-03T00:33:54","date_gmt":"2024-07-02T16:33:54","guid":{"rendered":"https:\/\/noobxiaomeng.top\/?p=366"},"modified":"2024-07-03T08:37:13","modified_gmt":"2024-07-03T00:37:13","slug":"cqt%ef%bc%9a0x01-qstring","status":"publish","type":"post","link":"https:\/\/noobxiaomeng.top\/index.php\/2024\/07\/03\/cqt%ef%bc%9a0x01-qstring\/","title":{"rendered":"C++Qt\uff1a0x01.QString\u7c7b\u521d\u6b65"},"content":{"rendered":"<p>\u5728\u6b64\u4e4b\u524d\u9700\u8981\u914d\u7f6eQt\u73af\u5883\uff1a<a href=\"https:\/\/noobxiaomeng.top\/index.php\/2024\/07\/03\/cqt%ef%bc%9a0x00-qtcode\/\">Qt\u73af\u5883\u914d\u7f6e<\/a><\/p>\n<h3>\u6570\u636e\u8f6c\u6362<\/h3>\n<pre><code class=\"language-C\">QString str1 = &quot;123&quot;;\n    QString str2 = &quot;456&quot;;\n\n    \/\/ \u6570\u636e\u8f6c\u6362 to int\n    int a1 = str1.toInt();\n    int a2 = str2.toInt();\n\n    qDebug() &lt;&lt; a1+a2;\n\n    \/\/ \u6570\u5b57\u8f6cQString\n    int a3 = 520;                               \/\/ 208h\n    QString str3 = QString::number(a3,16);      \/\/ \u8f6c\u4e3a16\u8fdb\u5236\n\n    qDebug() &lt;&lt; str3;\n<\/code><\/pre>\n<h3>\u5b57\u7b26\u4e32\u62fc\u63a5<\/h3>\n<pre><code class=\"language-C\"> \/\/ \u5b57\u7b26\u4e32\u62fc\u63a5\n    QString str4 = &quot;hello&quot;;\n    QString str5 = &quot;_&quot;;\n    QString str6 = &quot;world&quot;;\n\n    qDebug() &lt;&lt; str4 + str5 + str6;             \/\/ &quot;+&quot;\u88ab\u91cd\u8f7d\u4e86\n<\/code><\/pre>\n<h3>\u8f6c\u6362\u5927\u5c0f\u5199<\/h3>\n<pre><code class=\"language-C\">\/\/\u8f6c\u6362\u5927\u5c0f\u5199\n    QString str7 = &quot;Qt&quot;;\n    QString str8 = str7.toLower();\n    qDebug() &lt;&lt; str8;\n    QString str9 = str4.toUpper();\n    qDebug() &lt;&lt; str9;<\/code><\/pre>\n<h3>\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6<\/h3>\n<pre><code class=\"language-C\">\/\/\u5224\u65ad\u5b57\u7b26\u957f\u5ea6\uff1a count\/size\/length\n    int len1 = str4.count();\n    int len2 = str4.size();\n    int len3 = str4.length();\n    \/\/\u957f\u5ea6\u4e3a5\n    qDebug() &lt;&lt; len1;\n    qDebug() &lt;&lt; len2;\n    qDebug() &lt;&lt; len3;\n<\/code><\/pre>\n<h3>\u7a7a\u683c\u6574\u7406<\/h3>\n<pre><code class=\"language-C\">\/\/\u53bb\u9664\u9996\u5c3e\u7a7a\u683c  trimmed\n    QString str10 = &quot;           OK                OK                OK            &quot;;\n    qDebug() &lt;&lt; str10;\n    QString str11 = str10.trimmed();\n    qDebug() &lt;&lt; str11;\n\n    \/\/\u7edf\u4e00\u7a7a\u683c\u683c\u5f0f\n    QString str12 = &quot;           OK                OK                OK            &quot;;\n    QString str13 = str12.simplified();\n    qDebug() &lt;&lt; str13;<\/code><\/pre>\n<h3>\u67e5\u627e\u5b57\u7b26\u4e32\u5143\u7d20<\/h3>\n<pre><code class=\"language-C\">\/\/\u83b7\u53d6\u6587\u4ef6\u540d\n    QString str14 = &quot;C:\\\\software\\\\IDA_Pro_v8.3_Portable\\\\ida64.exe&quot;;\n    int last = str14.lastIndexOf(&quot;\\\\&quot;);     \/\/\u622a\u53d6\u6700\u540e\u4e00\u4e2a&#039;\\&#039;\u4e4b\u540e\u7684\u5b57\u7b26\u5143\u7d20\u4e0b\u6807\uff0c\u7531\u4e8e&#039;\\&#039;\u662f\u8f6c\u4e49\u5b57\u7b26\uff0c\u6240\u4ee5\u6b64\u5904\u6253\u4e24\u4e2a\n    int exe = str14.indexOf(&quot;.exe&quot;);        \/\/\u622a\u53d6.exe\u4e4b\u524d\u7684\u5b57\u7b26\u5143\u7d20\u4e0b\u6807\uff0c\u8fd9\u6837\u5c31\u80fd\u83b7\u53d6\u6587\u4ef6\u540d\u4e86\n    qDebug() &lt;&lt; last &lt;&lt; &quot;  &quot; &lt;&lt; exe;        \/\/\u6253\u5370\u6587\u4ef6\u4e0b\u6807\uff0c\u5206\u522b\u662f[33]\u548c[39]<\/code><\/pre>\n<h3>\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a<\/h3>\n<pre><code class=\"language-C\">\/\/\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a\uff1a isNull,isEmpty\n    QString str15;\n    QString str16 = &quot;&quot;;\n\n    qDebug() &lt;&lt; str15.isNull() &lt;&lt; &quot;  &quot; &lt;&lt; str15.isEmpty();  \/\/\u7ed3\u679c\u90fd\u8fd4\u56detrue\n    qDebug() &lt;&lt; str16.isNull() &lt;&lt; &quot;  &quot; &lt;&lt; str16.isEmpty();  \/\/\u524d\u8005\u8fd4\u56defalse\uff0c\u5373\u5305\u542b&#039;\\0&#039;<\/code><\/pre>\n<h3>\u5224\u65ad\u662f\u5426\u5305\u542b\u67d0\u5b57\u7b26\u4e32<\/h3>\n<pre><code class=\"language-C\">\/\/\u5224\u65ad\u662f\u5426\u5305\u542b\u67d0\u4e2a\u5b57\u7b26\u4e32\n    QString str17 = &quot;Fuck you&quot;;\n    \/\/\u662f\u5426\u5305\u542bFuck\n    int index = str17.contains(&quot;fuck&quot;,Qt::CaseInsensitive);   \/\/\u5305\u542b\u5219\u8fd4\u56de1\uff0c\u5426\u5219\u8fd4\u56de0\n    \/\/CaseSensitive\u533a\u5206\u5927\u5c0f\u5199\uff0cCaseInsensitive\u4e0d\u533a\u5206\u5927\u5c0f\u5199\n    if(index){\n        str17 = &quot;F**k you&quot;;\n    }\n    qDebug() &lt;&lt; str17;<\/code><\/pre>\n<h3>\u5224\u65ad\u5b57\u7b26\u4e32\u4ee5\u67d0\u524d\u7f00\u5f00\u5934\/\u540e\u7f00\u7ed3\u5c3e<\/h3>\n<pre><code class=\"language-C\">\/\/\u662f\u5426\u4ee5\u7279\u5b9a\u540e\u7f00\u7ed3\u5c3e &quot;.exe&quot; and &quot;.elf&quot;\n    QString pe = &quot;test.exe&quot;;\n    bool isexe = pe.endsWith(&quot;.exe&quot;,Qt::CaseSensitive);\n    if(isexe)\n        qDebug() &lt;&lt; &quot;It is a PE project.&quot;;\n    else\n        qDebug() &lt;&lt; &quot;It isn&#039;t a PE project.&quot;;\n\n    \/\/\u662f\u5426\u4ee5\u7279\u5b9a\u5b57\u7b26\u4e32\u5f00\u5934\n    QString elf = &quot;test.elf&quot;;\n    bool istest = elf.startsWith(&quot;test&quot;,Qt::CaseInsensitive);\n    if(istest)\n        qDebug() &lt;&lt; &quot;O\u6d4b\u8bd5\u7a0b\u5e8fO&quot;;\n    else\n        qDebug() &lt;&lt; &quot;@\u975e\u6d4b\u8bd5@&quot;;<\/code><\/pre>\n<h3>\u5b8c\u6574\u4ee3\u7801<\/h3>\n<pre><code class=\"language-Cpp\">#include &lt;QCoreApplication&gt;\n#include &lt;QDebug&gt;\n#include &lt;QString&gt;\n\n\/*\nQString \u91c7\u7528uniocde\u7f16\u7801\uff0c\u6bcf\u4e00\u4e2a\u5b57\u7b26\u662f\u4e00\u4e2a16\u4f4d\u7684Qchar\uff0c\u5373\u53ef\u517c\u5bb9\u4e2d\u6587\n*\/\n\nint main(int argc, char *argv[])\n{\n    QCoreApplication a(argc, argv);\n\n    QString str1 = &quot;123&quot;;\n    QString str2 = &quot;456&quot;;\n\n    \/\/ \u6570\u636e\u8f6c\u6362 to int\n    int a1 = str1.toInt();\n    int a2 = str2.toInt();\n\n    qDebug() &lt;&lt; a1+a2;\n\n    \/\/ \u6570\u5b57\u8f6cQString\n    int a3 = 520;                               \/\/ 208h\n    QString str3 = QString::number(a3,16);      \/\/ \u8f6c\u4e3a16\u8fdb\u5236\n\n    qDebug() &lt;&lt; str3;\n\n    \/\/ \u5b57\u7b26\u4e32\u62fc\u63a5\n    QString str4 = &quot;hello&quot;;\n    QString str5 = &quot;_&quot;;\n    QString str6 = &quot;world&quot;;\n\n    qDebug() &lt;&lt; str4 + str5 + str6;             \/\/ &quot;+&quot;\u88ab\u91cd\u8f7d\u4e86\n\n    \/\/\u8f6c\u6362\u5927\u5c0f\u5199\n    QString str7 = &quot;Qt&quot;;\n    QString str8 = str7.toLower();\n    qDebug() &lt;&lt; str8;\n    QString str9 = str4.toUpper();\n    qDebug() &lt;&lt; str9;\n\n    \/\/\u5224\u65ad\u5b57\u7b26\u957f\u5ea6\uff1a count\/size\/length\n    int len1 = str4.count();\n    int len2 = str4.size();\n    int len3 = str4.length();\n    \/\/\u957f\u5ea6\u4e3a5\n    qDebug() &lt;&lt; len1;\n    qDebug() &lt;&lt; len2;\n    qDebug() &lt;&lt; len3;\n\n    \/\/\u53bb\u9664\u9996\u5c3e\u7a7a\u683c  trimmed\n    QString str10 = &quot;           OK                OK                OK            &quot;;\n    qDebug() &lt;&lt; str10;\n    QString str11 = str10.trimmed();\n    qDebug() &lt;&lt; str11;\n\n    \/\/\u7edf\u4e00\u7a7a\u683c\u683c\u5f0f\n    QString str12 = &quot;           OK                OK                OK            &quot;;\n    QString str13 = str12.simplified();\n    qDebug() &lt;&lt; str13;\n\n    \/\/\u83b7\u53d6\u6587\u4ef6\u540d\n    QString str14 = &quot;C:\\\\software\\\\IDA_Pro_v8.3_Portable\\\\ida64.exe&quot;;\n    int last = str14.lastIndexOf(&quot;\\\\&quot;);     \/\/\u622a\u53d6\u6700\u540e\u4e00\u4e2a&#039;\\&#039;\u4e4b\u540e\u7684\u5b57\u7b26\u5143\u7d20\u4e0b\u6807\uff0c\u7531\u4e8e&#039;\\&#039;\u662f\u8f6c\u4e49\u5b57\u7b26\uff0c\u6240\u4ee5\u6b64\u5904\u6253\u4e24\u4e2a\n    int exe = str14.indexOf(&quot;.exe&quot;);        \/\/\u622a\u53d6.exe\u4e4b\u524d\u7684\u5b57\u7b26\u5143\u7d20\u4e0b\u6807\uff0c\u8fd9\u6837\u5c31\u80fd\u83b7\u53d6\u6587\u4ef6\u540d\u4e86\n    qDebug() &lt;&lt; last &lt;&lt; &quot;  &quot; &lt;&lt; exe;        \/\/\u6253\u5370\u6587\u4ef6\u4e0b\u6807\uff0c\u5206\u522b\u662f[33]\u548c[39]\n\n    \/\/\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a\uff1a isNull,isEmpty\n    QString str15;\n    QString str16 = &quot;&quot;;\n\n    qDebug() &lt;&lt; str15.isNull() &lt;&lt; &quot;  &quot; &lt;&lt; str15.isEmpty();  \/\/\u7ed3\u679c\u90fd\u8fd4\u56detrue\n    qDebug() &lt;&lt; str16.isNull() &lt;&lt; &quot;  &quot; &lt;&lt; str16.isEmpty();  \/\/\u524d\u8005\u8fd4\u56defalse\uff0c\u5373\u5305\u542b&#039;\\0&#039;\n\n    \/\/\u5224\u65ad\u662f\u5426\u5305\u542b\u67d0\u4e2a\u5b57\u7b26\u4e32\n    QString str17 = &quot;Fuck you&quot;;\n    \/\/\u662f\u5426\u5305\u542bFuck\n    int index = str17.contains(&quot;fuck&quot;,Qt::CaseInsensitive);   \/\/\u5305\u542b\u5219\u8fd4\u56de1\uff0c\u5426\u5219\u8fd4\u56de0\n    \/\/CaseSensitive\u533a\u5206\u5927\u5c0f\u5199\uff0cCaseInsensitive\u4e0d\u533a\u5206\u5927\u5c0f\u5199\n    if(index){\n        str17 = &quot;F**k you&quot;;\n    }\n    qDebug() &lt;&lt; str17;\n\n    \/\/\u662f\u5426\u4ee5\u7279\u5b9a\u540e\u7f00\u7ed3\u5c3e &quot;.exe&quot; and &quot;.elf&quot;\n    QString pe = &quot;test.exe&quot;;\n    bool isexe = pe.endsWith(&quot;.exe&quot;,Qt::CaseSensitive);\n    if(isexe)\n        qDebug() &lt;&lt; &quot;It is a PE project.&quot;;\n    else\n        qDebug() &lt;&lt; &quot;It isn&#039;t a PE project.&quot;;\n\n    \/\/\u662f\u5426\u4ee5\u7279\u5b9a\u5b57\u7b26\u4e32\u5f00\u5934\n    QString elf = &quot;test.elf&quot;;\n    bool istest = elf.startsWith(&quot;test&quot;,Qt::CaseInsensitive);\n    if(istest)\n        qDebug() &lt;&lt; &quot;O\u6d4b\u8bd5\u7a0b\u5e8fO&quot;;\n    else\n        qDebug() &lt;&lt; &quot;@\u975e\u6d4b\u8bd5@&quot;;\n\n    return a.exec();\n}\n<\/code><\/pre>\n<h3>\u8fd0\u884c\u6548\u679c<\/h3>\n<p><a href=\"https:\/\/noobxiaomeng.top\/wp-content\/uploads\/2024\/07\/Pasted-image-20240703001005.png\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/noobxiaomeng.top\/wp-content\/uploads\/2024\/07\/Pasted-image-20240703001005.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/noobxiaomeng.top\/wp-content\/uploads\/2024\/07\/Pasted-image-20240703001005.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6b64\u4e4b\u524d\u9700\u8981\u914d\u7f6eQt\u73af\u5883\uff1aQt\u73af\u5883\u914d\u7f6e \u6570\u636e\u8f6c\u6362 QString str1 = &quot;123&quot; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":369,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-366","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c_qt"],"_links":{"self":[{"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/posts\/366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/comments?post=366"}],"version-history":[{"count":1,"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"predecessor-version":[{"id":370,"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/posts\/366\/revisions\/370"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/media\/369"}],"wp:attachment":[{"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/noobxiaomeng.top\/index.php\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}