Qt“私有时隙:这是什么? [英] Qt "private slots:" what is this?

查看:113
本文介绍了Qt“私有时隙:这是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我明白如何使用它,但它的语法困扰我。什么是private slots:??



我从来没有见过private关键字和之前的类定义。这里是否有一些奇特的C ++魔术?



并且这里的例子:

  #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);

...


解决方案

插槽是C ++的Qt特定扩展。它只有在通过Qt的预处理器Meta-Object Compiler(moc)发送代码之后才编译。有关文档,请参见 http://doc.qt.io/qt-5/moc.html 。 / p>

编辑:正如Frank指出的,只有链接才需要moc。额外的关键字使用标准预处理程序#defined。


I understand how to use it, but the syntax of it bothers me. What is "private slots:" doing?

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?

And example 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 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.

Edit: As Frank points out, moc is only required for linking. The extra keywords are #defined away with the standard preprocessor.

这篇关于Qt“私有时隙:这是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆