My first Qt application - a multiple-state window with a menu
That's a good first Qt program.  Most of my comments are preferences rather than rules, but I'll try to provide justifications.

In main(), no need to new

I would write

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    MainWindow mw;
    mw.show();
    return app.exec();
}


That way, you don't need to remember to delete the objects app and mw.  (You can argue that there's no need to clean up when you're exiting, but I find it helps to avoid false-positives when I'm checking memory correctness with Valgrind).

In constructors, prefer to use initializers

I can write

MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent),
      layout(new QStackedLayout(this))
{


This allows us to declare layout as a const pointer, for increased safety:

QStackedLayout *const layout;


Note that I've passed this to the QStackedLayout constructor: that ensures that it always has an owner that's responsible for deleting it, and it installs it as the layout manager for the MainWindow widget (saving us a line of code).

Use new-style connect() when you can

Unless you don't know the complete type of the objects being connected, you can connect by pointer-to-member-function.  This allows more errors to be caught at compilation time (a Good Thing):

MenuPage::MenuPage(MainWindow *parent)
    : QWidget(parent),
      layout(new QVBoxLayout(this)),
      signalMapper(new QSignalMapper(this))
{
    void(QSignalMapper::*signal)(int) = &amp;QSignalMapper::mapped;
    connect(signalMapper, signal, parent, &amp;MainWindow::setPage);
}


However, I'd move the signal mapper and connect() call up into MainWindow, so that MenuPage doesn't need to know about its parent.

Reduce coupling

Both MainWindow and MenuPage need to know about MainWindow in their constructors.  Although we can simply pass a QObject, and connect by name, there's still coupling because they impose requirements on the slots exposed, so they can't be used more generally.

The way to fix this coupling is for the pages to emit a signal to indicate user actions; the MainWindow (which knows about its contents) can then connect those signals to the relevant actions.

MenuPage then looks like

public:
    explicit MenuPage(QWidget *parent);
signals:
    void buttonPressed(int button_number);


and its constructor is now

MenuPage::MenuPage(QWidget *parent)
    : QWidget(parent),
      layout(new QVBoxLayout(this)),
      signalMapper(new QSignalMapper(this))
{
    void(QSignalMapper::*signal)(int) = &amp;QSignalMapper::mapped;
    connect(signalMapper, signal, this, &amp;MenuPage::buttonPressed);
}


(The temporary variable signal is to avoid the problem of connecting overloaded signals and slots in Qt 5).

In MainWindow, we connect it directly:

connect(menuPage, &amp;MenuPage::buttonPressed, layout, &amp;QStackedLayout::setCurrentIndex);


We can do something similar in SubPage, but this is a little simpler, as we don't have an overloaded signal.  So just create a signal (call it done(), perhaps) and make the page's constructor connect the button's clicked() to the page's done().

A memory leak

Here, we allocate a new QString, which is never released:

QString label = (new QString("Page %1")) -&gt; arg(nButtons);


It's easy to fix this - QString objects are fine to pass by value:

QString label = QString(tr("Page %1")).arg(nButtons);


Allow for translation

If you get into the habit of using tr() on all your user-facing strings, you've made a good start on internationalizing your application



Full worked example

I've inlined the methods just to make this smaller - I don't expect that in a real, multiple-source-file program.

#include &lt;QWidget&gt;
#include &lt;QPushButton&gt;
#include &lt;QStackedLayout&gt;
#include &lt;QVBoxLayout&gt;
#include &lt;QSignalMapper&gt;
#include &lt;QLabel&gt;




class MenuPage : public QWidget
{
    Q_OBJECT

public:
    explicit MenuPage(QWidget *parent)
        : QWidget(parent),
          layout(new QVBoxLayout(this)),
          signalMapper(new QSignalMapper(this))
    {
        void(QSignalMapper::*signal)(int) = &amp;QSignalMapper::mapped;
        connect(signalMapper, signal, this, &amp;MenuPage::buttonPressed);
    }

    void addButton()
    {
        ++nButtons;

        QString label = QString(tr("Page %1")).arg(nButtons);
        QPushButton *button = new QPushButton(label, this);
        layout-&gt;addWidget(button);

        signalMapper-&gt;setMapping(button, nButtons);
        connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
    }

signals:
    void buttonPressed(int button_number);

private:
    QVBoxLayout *const layout;
    QSignalMapper *const signalMapper;
    int nButtons = 0;
};


    

class SubPage : public QWidget
{
    Q_OBJECT

public:
    explicit SubPage(const QString&amp; messageText, QWidget *parent)
        : QWidget(parent),
          message(new QLabel(messageText, this)),
          backButton(new QPushButton(tr("Back"), this))
    {
        QVBoxLayout *const layout = new QVBoxLayout(this);
        layout-&gt;addWidget(message);
        layout-&gt;addWidget(backButton);
        connect(backButton, &amp;QPushButton::clicked, this, &amp;SubPage::done);
    }

signals:
    void done();

private:
    QLabel *const message;
    QPushButton *const backButton;
};




class MainWindow : public QWidget
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0)
        : QWidget(parent),
          layout(new QStackedLayout(this))
    {
        setWindowTitle(tr("Application"));
        MenuPage *const menuPage = new MenuPage(this);
        SubPage  *const page1    = new SubPage(tr("This is page one."), this);
        SubPage  *const page2    = new SubPage(tr("This is page two."), this);

        layout-&gt;addWidget(menuPage);
        layout-&gt;addWidget(page1);
        layout-&gt;addWidget(page2);
        layout-&gt;setCurrentIndex(0);

        menuPage-&gt;addButton();
        menuPage-&gt;addButton();
        connect(menuPage, &amp;MenuPage::buttonPressed, layout, &amp;QStackedLayout::setCurrentIndex);
        connect(page1, &amp;SubPage::done, this, &amp;MainWindow::goToMenu);
        connect(page2, &amp;SubPage::done, this, &amp;MainWindow::goToMenu);
    }

private:
    QStackedLayout *const layout;
public slots:
    void setPage(int index)
    {
        layout-&gt;setCurrentIndex(index);
    }

    void goToMenu()
    {
        layout-&gt;setCurrentIndex(0);
    }
};


    

#include &lt;QApplication&gt;

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    MainWindow mw;
    mw.show();
    return app.exec();
}

#include "165088_moc.cpp"