pyQT 插槽装饰器什么是C++等价物

pyQT slot decorator what is the C++ equivalent

本文关键字:C++ 等价物 什么 插槽 pyQT      更新时间:2023-10-16

我有一个关于QT和PyQT的初学者水平的问题。我正在使用Python的PyQt绑定,并有以下简单的代码。根据一些谷歌搜索,插槽装饰器似乎主要用于将方法显式标记为插槽。我的问题是,如果我用C++编写此代码,等效方法是什么?

    @QtCore.pyqtSlot()
    def openDialog(self):
        self.myDialog.show()

要在C++/Qt中创建槽,请使用以下语法:

class MyClass : public QObject {
   Q_OBJECT
public slots:
   void mySlot(/* parameters here */); // Definition may be here or in the implementation file
};

如果您使用的是no_keywords选项(这意味着您不想将Qt关键字用作普通C++关键字),只需将slots替换为Q_SLOTS

您可以在官方文档中找到更多信息:http://qt-project.org/doc/qt-5.0/qtcore/signalsandslots.html