{"id":11423,"date":"2024-01-16T17:35:53","date_gmt":"2024-01-16T09:35:53","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=11423"},"modified":"2024-03-26T16:32:29","modified_gmt":"2024-03-26T08:32:29","slug":"qt%e4%bf%a1%e5%8f%b7%e4%b8%8e%e6%a7%bd","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=11423","title":{"rendered":"Qt\u4fe1\u53f7\u4e0e\u69fd"},"content":{"rendered":"<p><a href=\"https:\/\/blog.csdn.net\/ccc369639963\/article\/details\/122665026\">https:\/\/blog.csdn.net\/ccc369639963\/article\/details\/122665026<\/a><br \/>\n<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/648165514\">https:\/\/zhuanlan.zhihu.com\/p\/648165514<\/a><\/p>\n<h3>windows\u4e4b\u95f4\u4fe1\u53f7\u4f20\u9012<\/h3>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53MyWindow\u53d1\u9001mySignal\u65f6\uff0cMainWindow\u7684handleSignal\u69fd\u51fd\u6570\u4f1a\u88ab\u8c03\u7528\uff0c\u5e76\u63a5\u6536\u5230\u4eceMyWindow\u53d1\u9001\u7684\u503c\u3002<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u5b9a\u4e49\u4f60\u7684\u4fe1\u53f7\u548c\u69fd\u51fd\u6570\u3002\u5728\u63a5\u6536\u4fe1\u53f7\u7684\u7a97\u53e3\u7c7b\u4e2d\uff0c\u4f60\u9700\u8981\u58f0\u660e\u4fe1\u53f7\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e2a\u69fd\u51fd\u6570\u6765\u5904\u7406\u4fe1\u53f7\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">\/\/ mywindow.h\n#ifndef MYWINDOW_H\n#define MYWINDOW_H\n\n#include &lt;QWidget&gt;\n\nclass MyWindow : public QWidget {\n    Q_OBJECT\npublic:\n    explicit MyWindow(QWidget *parent = nullptr);\n\nsignals:\n    void mySignal(int value);\n\nprivate:\n    \/\/ \u89e6\u53d1\u4fe1\u53f7\u7684\u90e8\u5206\n};\n\n#endif \/\/ MYWINDOW_H<\/code><\/pre>\n<ul>\n<li>\u7136\u540e\uff0c\u5728\u4f60\u60f3\u8981\u53d1\u9001\u4fe1\u53f7\u7684\u5730\u65b9\uff0c\u4f7f\u7528emit\u5173\u952e\u5b57\u53d1\u9001\u4fe1\u53f7\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">\/\/ mywindow.cpp\n#include &quot;mywindow.h&quot;\n\nMyWindow::MyWindow(QWidget *parent) : QWidget(parent) {\n    \/\/ \u6784\u9020\u51fd\u6570\u7684\u5176\u4ed6\u90e8\u5206\n\n    \/\/ \u5f53\u4f60\u60f3\u8981\u53d1\u9001\u4fe1\u53f7\u65f6\n    emit mySignal(10); \/\/ \u5047\u8bbe\u53d1\u9001\u7684\u503c\u662f10\n}<\/code><\/pre>\n<ul>\n<li>\u5728\u53e6\u4e00\u4e2a\u7a97\u53e3\u4e2d\uff0c\u4f60\u9700\u8981\u58f0\u660e\u4f60\u60f3\u8981\u8fde\u63a5\u7684\u4fe1\u53f7\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e2a\u69fd\u51fd\u6570\u6765\u5904\u7406\u5b83\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">\/\/ mainwindow.h\n#ifndef MAINWINDOW_H\n#define MAINWINDOW_H\n\n#include &lt;QMainWindow&gt;\n\nclass MainWindow : public QMainWindow {\n    Q_OBJECT\n\npublic:\n    MainWindow(QWidget *parent = nullptr);\n    ~MainWindow();\n\npublic slots:\n    void handleSignal(int value);\n};\n\n#endif \/\/ MAINWINDOW_H<\/code><\/pre>\n<ul>\n<li>\u5728cpp\u6587\u4ef6\u4e2d\u5b9e\u73b0\u69fd\u51fd\u6570\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">\/\/ mainwindow.cpp\n#include &quot;mainwindow.h&quot;\n#include &lt;QDebug&gt;\n\nMainWindow::MainWindow(QWidget *parent)\n    : QMainWindow(parent) {\n    \/\/ MainWindow\u7684\u6784\u9020\u51fd\u6570\n}\n\nMainWindow::~MainWindow() {\n    \/\/ MainWindow\u7684\u6790\u6784\u51fd\u6570\n}\n\nvoid MainWindow::handleSignal(int value) {\n    qDebug() &lt;&lt; &quot;Received signal with value:&quot; &lt;&lt; value;\n    \/\/ \u5904\u7406\u4fe1\u53f7\u7684\u5176\u4ed6\u4ee3\u7801\n}<\/code><\/pre>\n<ul>\n<li>\u6700\u540e\uff0c\u4f60\u9700\u8981\u8fde\u63a5\u8fd9\u4e24\u4e2a\u4fe1\u53f7\u548c\u69fd\u51fd\u6570\u3002\u8fd9\u901a\u5e38\u5728\u7a97\u53e3\u7684\u6784\u9020\u51fd\u6570\u4e2d\u5b8c\u6210\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">\/\/ main.cpp\n#include &quot;mywindow.h&quot;\n#include &quot;mainwindow.h&quot;\n#include &lt;QApplication&gt;\n\nint main(int argc, char *argv[]) {\n    QApplication a(argc, argv);\n\n    MyWindow myWindow;\n    MainWindow mainWindow;\n\n    \/\/ \u8fde\u63a5\u4fe1\u53f7\u548c\u69fd\n    QObject::connect(&amp;myWindow, &amp;MyWindow::mySignal, &amp;mainWindow, &amp;MainWindow::handleSignal);\n\n    myWindow.show();\n    mainWindow.show();\n\n    return a.exec();\n}<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"11423\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>https:\/\/blog.csdn.net\/ccc369639963\/article\/details [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[894],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/11423"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11423"}],"version-history":[{"count":6,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/11423\/revisions"}],"predecessor-version":[{"id":12636,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/11423\/revisions\/12636"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11423"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}