Hi all,

How are you? I just discovered this great site. I'm new to both Qt and C++ (migrated from simple C programming for DOS) and I don't really know what I'm doing. But I really want to learn - so, I started trying. Unfortunately things don't work for me because I'm missing some key points. To get some feel of what's going on, I'm trying to write a code where I use my own function to exit a program. Please be kind enough to look at my code and suggest what I'm doing wrong. When I click on "Exit", the program exits, but "My Exit" won't work.
The main thing I'm trying to learn here is: How do I implement my own function that does something when a QPushButton is clicked? I guess I always need to define a new object through my own subclass that inherits from QObject? Is that correct?
Here's my pathetic code that won't work:

#include <QApplication>
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>
using namespace std;

class MyClass : public QObject
{
Q_OBJECT

public:
MyClass (QObject *parent = 0);
public slots:
void myExit();
};

MyClass::MyClass(QObject *parent)
: QObject(parent)
{
}

void MyClass::myExit() {exit(1)};

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

MyClass a;

QApplication app(argc, argv);
QWidget window;

QHBoxLayout* mainLayout = new QHBoxLayout(&window);
QPushButton* cancelButton = new QPushButton("My Exit");
QPushButton* exitButton = new QPushButton("Exit");

mainLayout->addWidget(cancelButton);
mainLayout->addWidget(exitButton);

QObject::connect(cancelButton, SIGNAL(clicked()), &a, SLOT(myExit()));
QObject::connect(exitButton, SIGNAL(clicked()), &app, SLOT(quit()));

window.show();
return app.exec();
}

Thanks and have a great day!