{"id":61988,"date":"2026-01-19T02:17:50","date_gmt":"2026-01-18T18:17:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/61988.html"},"modified":"2026-01-19T02:17:50","modified_gmt":"2026-01-18T18:17:50","slug":"qt%e9%ab%98%e9%98%b6%e6%97%a5%e8%ae%b0003","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/61988.html","title":{"rendered":"QT\u9ad8\u9636\u65e5\u8bb0003"},"content":{"rendered":"<\/p>\n<p>\u7f51\u7edc\u901a\u4fe1QSocket<\/p>\n<p>\u7f51\u7edc\u901a\u4fe1\u5206\u4e3aTCP\/UDP<\/p>\n<p>\u5176\u4ed6\u7684\u65b9\u5f0f\u4e5f\u662f\u7531\u6b64\u4e8c\u7c7b\u5ef6\u4f38\u51fa\u6765\u7684\u3002<br \/>\nQT\u5305\u62ec\u4e86QTcpSocket,QTcpServer,QUdpServer,QUdpSocket<\/p>\n<p>\u5728\u9879\u76ee\u4e2d\u8981\u52a0\u5165<br \/>\nQT &#043;&#061;&#8230;.. network<\/p>\n<p>\u4e00\u3001QTcpServer<br \/>\n\u65b9\u6cd5<br \/>\nclose();<br \/>\nerrorString();<br \/>\nhasPendingConnections();<br \/>\nisListening();<br \/>\nlisten()<br \/>\nmaxPendingConnection();<br \/>\nnetPendingConnection();<br \/>\npauseAccepting();<br \/>\nproxy();<br \/>\nresumeAccepting();<br \/>\nserverAddress();<br \/>\nserverError();<br \/>\nserverPort();<\/p>\n<p>\nsetMaxPendingConnection(int num);<br \/>\nsetProxy(QNetworkProxy &amp;proxy);<br \/>\nsetSocketDescriptor();<br \/>\nsocketDescriptor();<br \/>\nwaitForNewConnection(int ms,bool timedOut&#061;nullptr);<br \/>\n\u2026\u2026<br \/>\n\u7ec6\u8282\u8fd8\u6709\u7684\u8bdd\u770b\u5e2e\u52a9\u6587\u6863<\/p>\n<p>\u793a\u4f8b&#xff1a;\u5b9a\u4e49<br \/>\n\u5f15\u7528<br \/>\n#include&lt;QTcpServer&gt;<\/p>\n<p>\u4e8c\u3001QTcpSocket&#xff0c;\u7ee7\u627f\u6765\u81eaQIODevice,\u540cQFile<br \/>\nconnectToHost(host,port,openmode,layer);<br \/>\n\u9700\u8981\u552f\u4e00\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53bb\u8fde\u63a5\u670d\u52a1\u5668\u3002<br \/>\n\u65b9\u6cd5\u6765\u81eaSocket\u5e95\u5c42\u7c7b<br \/>\natEnd();<br \/>\nbytesAvailable()<br \/>\nbytesToWrite();<br \/>\ncanReadLine();<br \/>\nclose();<br \/>\ncommitTransaction();<br \/>\ncurrentReadChannel();<br \/>\ncurrentWriteChannel();<br \/>\nerrorString();<br \/>\ngetChar<br \/>\nisOpen<br \/>\nisReadable();<br \/>\nisSequential();<br \/>\nisTextModeEnabled();<br \/>\nisTransactionStarted();<br \/>\nisWritable();<br \/>\nopen();<br \/>\nopenMode();<br \/>\npeek();<br \/>\npos();<br \/>\nputChar<br \/>\nread();\/\/c&#043;&#043;\u98ce\u683c\u548cQT\u98ce\u683c\u7684\u4e24\u79cd\u8bfb\u6cd5\u3002<br \/>\nreadAll<br \/>\nreadChannelCount();<br \/>\nreadLine()<br \/>\nreset();<br \/>\nrollbackTransaction();<br \/>\nseek();<br \/>\nsetCurrentReadChannel();<br \/>\nsetCurrentWriteChannel();<br \/>\nsetTextModeEnabled();<br \/>\nsize<br \/>\nskip<br \/>\nstartTransaction();<br \/>\nungetChar();<br \/>\nwaitForBytesWritten();<br \/>\nwaitForReadyRead();<br \/>\nwrite();\/\/c&#043;&#043;\u98ce\u683c\u548cQT\u98ce\u683c\u7684\u4e24\u79cd\u5199\u6cd5\u3002<br \/>\nwriteChannelCount();<br \/>\n\u7b49\u7b49\u65b9\u6cd5\u548c\u529f\u80fd\u51fd\u6570\u3002<br \/>\n\u4fe1\u606f\u53f7<br \/>\nconnected<br \/>\ndisconnected<br \/>\nerror<\/p>\n<p>QIODevice\u7c7b\u7684\u4fe1\u53f7<br \/>\nreadRead();<br \/>\nreadChannelFinished<br \/>\naboutToClose();<br \/>\nbytesWritten();<br \/>\nchannelBytesWritten<br \/>\nchannelReadyRead<\/p>\n<p>QIODevice\u7c7b\u7684\u65b9\u6cd5<br \/>\nreadData();<br \/>\nreadLineData();<br \/>\nsetErrorString();<br \/>\nsetOpenMode<br \/>\nwriteData();<\/p>\n<p>\u5176\u4ed6\u7684\u65b9\u6cd5\u7531\u5e2e\u52a9\u6587\u4ef6\u53bb\u67e5\u8be2\u3002<\/p>\n<p>\n\u91cd\u70b9&#xff1a;<br \/>\n\u5728\u591a\u7ebf\u7a0b\u4e2d\u3002\u4e3b\u7ebf\u7a0b\u5b9a\u4e49\u7684QTcpSocket\u5bf9\u8c61&#xff0c;\u4e0d\u80fd\u5728\u5b50\u7ebf\u7a0b\u91cc\u4f7f\u7528\u3002\u53ea\u6709\u5728\u5b50\u7ebf\u7a0b\u91cc\u521b\u5efa\u7684\u624d\u53ef\u4ee5\u3002\u6240\u4ee5\u3002\u6211\u4eec\u5fc5\u987b\u5728\u4e3b\u7ebf\u7a0b&#xff0c;\u628a\u8fde\u63a5\u63cf\u8ff0\u5185\u5bb9\u4f20\u7ed9\u5b50\u7ebf\u7a0b&#xff0c;\u5728\u5b50\u7ebf\u7a0b\u901a\u8fc7\u8be5\u5185\u5bb9\u521b\u5efa\u4e00\u4e2a\u65b0\u7684QTcpSocket\u5bf9\u50cf\u3002\u624d\u53ef\u4ee5\u5de5\u4f5c\u3002<br \/>\n\u8fd9\u6837\u7684\u8bdd&#xff0c;\u6211\u4eec\u9700\u8981\u91cd\u5199QTcpServer-&gt;incomingConnection(qintptr socketDescriptor);\u65b9\u6cd5\u3002<br \/>\n\u8fd9\u4e2a\u65b9\u6cd5\u5728\u6709\u4eba\u8fde\u63a5\u5230\u670d\u52a1\u5668\u7684\u65f6\u5019&#xff0c;\u81ea\u52a8\u88abQT\u6846\u67b6\u8c03\u7528\u7684\u3002\u6211\u4eec\u53ea\u8981\u5728\u8fd9\u4e2a\u51fd\u6570\u91cc&#xff0c;\u901a\u8fc7\u4fe1\u53f7\u7684\u65b9\u5f0f\u628a\u8fd9\u4e2asocketDescriptor\u5185\u5bb9\u53d1\u9001\u51fa\u53bb\u3002\u8fd9\u6837\u7684\u8bdd&#xff0c;\u6211\u4eec\u9700\u8981\u91cd\u65b0\u4f5c\u4e00\u4e2a\u7c7b\u7ee7\u627fQTcpServer\u7c7b\u3002<br \/>\n\u7528\u8fd9\u4e2a\u7c7b\u6765\u4ee3\u66ffQTcpServer\u7c7b\u4f7f\u7528\u3002\u8fd9\u6837\u7684\u8bdd&#xff0c;\u6211\u4eec\u5c31\u4e0d\u9700\u8981\u7ed1\u5b9anewConnection\u4e86\u3002\u800c\u662f\u5e2e\u52a9\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u4fe1\u53f7\u5982myConnection&#xff0c;\u5f97\u5230\u8fd9\u4e2a\u53d1\u9001\u51fa\u6765\u7684socketDescriptor\u4fe1\u606f\u3002\u4f20\u7ed9\u6211\u4eec\u5b50\u7a0b\u5e8f&#xff0c;\u5728\u5b50\u7a0b\u5e8f\u91cc\u518dnew \u4e00\u4e2aQTcpSocket\u5bf9\u50cf\u3002\u4f7f\u7528socket-&gt;setSocketDescriptor(sockDescriptor&#xff09;;\u7684\u65b9\u6cd5\u3002\u8fd9\u6837\u7684\u8bdd&#xff0c;\u5c31\u7b97\u53ef\u4ee5\u628a\u8fde\u63a5\u8005\u7684\u4fe1\u606f\u4f20\u7ed9\u5b50\u7ebf\u7a0b&#xff0c;\u518d\u521b\u5efa\u5c5e\u4e8e\u5b50\u7ebf\u7a0b\u5185\u90e8\u7684QTcpSocket\u5bf9\u50cf\u6765\u5de5\u4f5c\u3002<\/p>\n<p>\u8fd9\u662f\u7f51\u7edc\u7f16\u7a0b\u4e2d&#xff0c;\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u6700\u8981\u5185\u5bb9\u3002<br \/>\n\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u7edc\u901a\u4fe1QSocket\u7f51\u7edc\u901a\u4fe1\u5206\u4e3aTCP\/UDP\u5176\u4ed6\u7684\u65b9\u5f0f\u4e5f\u662f\u7531\u6b64\u4e8c\u7c7b\u5ef6\u4f38\u51fa\u6765\u7684\u3002<br \/>\nQT\u5305\u62ec\u4e86QTcpSocket,QTcpServer,QUdpServer,QUdpSocket\u5728\u9879\u76ee\u4e2d\u8981\u52a0\u5165<br \/>\nQT &#8230;.. network\u4e00\u3001QTcpServer<br \/>\n\u65b9\u6cd5<br \/>\nclose();<br \/>\nerrorString();<br \/>\nhasPendingConnections();<br \/>\nisListening();<br \/>\nlisten()<br \/>\nmaxPendingConnection();<br \/>\nnetPendingCon<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[218,190],"topic":[],"class_list":["post-61988","post","type-post","status-publish","format-standard","hentry","category-server","tag-qt","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>QT\u9ad8\u9636\u65e5\u8bb0003 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/61988.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"QT\u9ad8\u9636\u65e5\u8bb0003 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7f51\u7edc\u901a\u4fe1QSocket\u7f51\u7edc\u901a\u4fe1\u5206\u4e3aTCP\/UDP\u5176\u4ed6\u7684\u65b9\u5f0f\u4e5f\u662f\u7531\u6b64\u4e8c\u7c7b\u5ef6\u4f38\u51fa\u6765\u7684\u3002 QT\u5305\u62ec\u4e86QTcpSocket,QTcpServer,QUdpServer,QUdpSocket\u5728\u9879\u76ee\u4e2d\u8981\u52a0\u5165 QT ..... network\u4e00\u3001QTcpServer \u65b9\u6cd5 close(); errorString(); hasPendingConnections(); isListening(); listen() maxPendingConnection(); netPendingCon\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/61988.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-18T18:17:50+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/61988.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/61988.html\",\"name\":\"QT\u9ad8\u9636\u65e5\u8bb0003 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-18T18:17:50+00:00\",\"dateModified\":\"2026-01-18T18:17:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/61988.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/61988.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/61988.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"QT\u9ad8\u9636\u65e5\u8bb0003\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"QT\u9ad8\u9636\u65e5\u8bb0003 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/61988.html","og_locale":"zh_CN","og_type":"article","og_title":"QT\u9ad8\u9636\u65e5\u8bb0003 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7f51\u7edc\u901a\u4fe1QSocket\u7f51\u7edc\u901a\u4fe1\u5206\u4e3aTCP\/UDP\u5176\u4ed6\u7684\u65b9\u5f0f\u4e5f\u662f\u7531\u6b64\u4e8c\u7c7b\u5ef6\u4f38\u51fa\u6765\u7684\u3002 QT\u5305\u62ec\u4e86QTcpSocket,QTcpServer,QUdpServer,QUdpSocket\u5728\u9879\u76ee\u4e2d\u8981\u52a0\u5165 QT ..... network\u4e00\u3001QTcpServer \u65b9\u6cd5 close(); errorString(); hasPendingConnections(); isListening(); listen() maxPendingConnection(); netPendingCon","og_url":"https:\/\/www.wsisp.com\/helps\/61988.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-18T18:17:50+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/61988.html","url":"https:\/\/www.wsisp.com\/helps\/61988.html","name":"QT\u9ad8\u9636\u65e5\u8bb0003 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-18T18:17:50+00:00","dateModified":"2026-01-18T18:17:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/61988.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/61988.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/61988.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"QT\u9ad8\u9636\u65e5\u8bb0003"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/61988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=61988"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/61988\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=61988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=61988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=61988"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=61988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}