Q: Proper subclassing with Qt Creator forms? I'm trying to make a class (AgilentSweeper) which is a subclass of QDockWidget so that I can design the layout for it in Qt Creator's form designer.  The header for the class looks like this:
// agilentsweeper.h
#ifndef AGILENTSWEEPER_H
#define AGILENTSWEEPER_H

#include <QDockWidget>

namespace Ui {
class AgilentSweeper;
}

class AgilentSweeper : public QDockWidget
{
    Q_OBJECT

public:
    explicit AgilentSweeper(QWidget *parent = 0);
    ~AgilentSweeper();

private:
    Ui::AgilentSweeper *ui;
};

#endif // AGILENTSWEEPER_H

and the source looks like
// agilentsweeper.cpp
#include "agilentsweeper.h"
#include "ui_agilentsweeper.h"
#include <QDockWidget>

AgilentSweeper::AgilentSweeper(QWidget *parent) :
    QDockWidget(parent),
    ui(new Ui::AgilentSweeper)
{
    ui->setupUi(this);
}

AgilentSweeper::~AgilentSweeper()
{
    delete ui;
}

In my main class h file I declare an instance of AgilentSweeper with 
#ifndef UTILSWEEP_H
#define UTILSWEEP_H

#include <QMainWindow>
#include <QDockWidget>
#include "agilentsweeper.h"

namespace Ui {
class UtilSweep;
}

class UtilSweep : public QMainWindow
{
    Q_OBJECT

public:
    explicit UtilSweep(QWidget *parent = 0);
    ~UtilSweep();

private:
    Ui::UtilSweep *ui;
    AgilentSweeper sweeper;
};

#endif // UTILSWEEP_H

And in the constructor for the main class I try to display "sweeper" on the side of the main window with 
#include "utilsweep.h"
#include "ui_utilsweep.h"
#include "agilentsweeper.h"
#include <QDockWidget>
#include <QMainWindow>

UtilSweep::UtilSweep(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::UtilSweep)
{
    ui->setupUi(this);
    addDockWidget(Qt::LeftDockWidgetArea,sweeper);
}

UtilSweep::~UtilSweep()
{
    delete ui;
}

However, I get an error that 
In constructor 'UtilSweep::UtilSweep(QWidget*)':  utilsweep.cpp:12: error: no matching function for call to 'UtilSweep::addDockWidget(Qt::DockWidgetArea, AgilentSweeper&)'
 addDockWidget(Qt::LeftDockWidgetArea,sweeper);

with the hint that
candidates are:  void QMainWindow::addDockWidget(Qt::DockWidgetArea, QDockWidget*)
 void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget);

Looking around, I found several other people with similar errors, but in their cases it seemed like either QDockWidget was not included in some places, or they were not using Q_OBJECT.  What's going wrong here?

A: addDockWidget() requires a pointer to a QDockWidget object as the second argument.  Your class variable sweeper is the object itself, not a pointer.  Your call to add addDockWidget() should be:
addDockWidget(Qt::LeftDockWidgetArea, &sweeper);


A: You should change the sweeper to be a pointer, and allocate it with new:
class UtilSweep : public QMainWindow
{
    ...
    AgilentSweeper *sweeper;
};

and
UtilSweep::UtilSweep(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::UtilSweep),
    sweeper(new AgilentSweeper(this))
{
    ui->setupUi(this);
    addDockWidget(Qt::LeftDockWidgetArea, sweeper);
}

