問題描述
我知道如何使用它,但它的語法讓我很困擾.什么是私人插槽:"在做什么?
I understand how to use it, but the syntax of it bothers me. What is "private slots:" doing?
我以前從未在類定義中看到 private 關鍵字和 : 之間的東西.這里有什么奇特的 C++ 魔法嗎?
I have never seen something between the private keyword and the : in a class definition before. Is there some fancy C++ magic going on here?
這里的例子:
#include <QObject>
class Counter : public QObject
{
Q_OBJECT
public:
Counter() { m_value = 0; }
int value() const { return m_value; }
public slots:
void setValue(int value);
...
推薦答案
Slots 是 C++ 的 Qt 特定擴展.它僅在通過 Qt 的預處理器元對象編譯器 (moc) 發送代碼后才進行編譯.見 http://doc.qt.io/qt-5/moc.html 用于文檔.
Slots are a Qt-specific extension of C++. It only compiles after sending the code through Qt's preprocessor, the Meta-Object Compiler (moc). See http://doc.qt.io/qt-5/moc.html for documentation.
正如弗蘭克指出的,只有鏈接才需要 moc.額外的關鍵字是用標準預處理器#defined 去掉的.
As Frank points out, moc is only required for linking. The extra keywords are #defined away with the standard preprocessor.
這篇關于Qt“私人插槽:"這是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!