1

I was doing Qt gui programming, in signals and slot section, I have the following syntax:

class Myclass
{
   public slot:

   signal:

}

Is this allowed to have a labelled region in class because normally I have seen this:

class Myclass
{
    public:
    //declarations
}

Can access modifiers have label also or it is a specific syntax in Qt?

Please clarify. Any help is appreciated. Thanks in advance.

Jake
  • 81
  • 1
  • 10

2 Answers2

3

These labels are Qt extensions to C++ (http://woboq.com/blog/how-qt-signals-slots-work.html). The MOC compiler parses the files and generates relevant glue logic. Details are in the link.

Sujay Phadke
  • 2,145
  • 1
  • 22
  • 41
0

Qt's headers define these preprocessor macros, so that when compiling, slot expands to the empty string, and signal expands to protected (in Qt 4) or public (in Qt 5). So as far as the C++ compiler is concerned, it sees something like:

class Myclass
{
   public :  /* was public slots */

   public:   /* was signals */

}

for your example above.

When the Meta-Object Compiler moc is run on the same declaration, it interprets the (un-substituted) Qt keywords, and uses them to compose meta-objects.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
  • As explained here: http://stackoverflow.com/questions/19129133/qt-signals-and-slots-permissions Signals are protected in Qt4 but are public in Qt5. – Sujay Phadke Dec 14 '15 at 11:54