user1849534 user1849534 - 3 months ago 8
C++ Question

getting the plain C++ implementation of a QT code

I was trying to figure out how this code will loke like in plain C++ without any dependency so I was using the

moc
compiler but apparently I'm wrong.

moc always returns

main.cpp:0: Note: No relevant classes found. No output generated.


the code is


#include <QApplication>
#include <QWidget>
#include <QPushButton>

class MyButton : public QWidget
{
public:
MyButton(QWidget *parent = 0);
};

MyButton::MyButton(QWidget *parent)
: QWidget(parent)
{
QPushButton *quit = new QPushButton("Quit", this);
quit->setGeometry(50, 40, 75, 30);

connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
}


int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MyButton window;

window.resize(250, 150);
window.move(300, 300);
window.setWindowTitle("button");
window.show();

return app.exec();
}


from http://www.zetcode.com/gui/qt4/firstprograms/


In general terms I'm interested in creating my own signal slot system using only the C++ standard library ( no boost signal, no QT, no nothing else ) so I'm doing this for research purpose and I'm only interested on the infrastructure about signals and slots.

Thanks.

Answer

Add the Q_OBJECT macro to the private section of your class, so moc converts it.

class MyButton : public QWidget
{
 Q_OBJECT
 public:
     MyButton(QWidget *parent = 0);
};

Here is what the documentation says.