My example below works and I think that's what you want. Compare with your code to see what's wrong 
Main.cpp:
#include <QtCore>
#include <QtGui>
#include <Test.h>
int main (int argc, char **argv)
{
Test *lDW = new Test("Test", w);
w->show();
return app.exec();
}
#include <QtCore>
#include <QtGui>
#include <Test.h>
int main (int argc, char **argv)
{
QApplication app (argc, argv);
QMainWindow *w = new QMainWindow();
Test *lDW = new Test("Test", w);
w->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Test.h:
#include <QtGui>
{
Q_OBJECT
public:
{
}
protected:
{
printf ("closeEvent!\n");
}
};
#include <QtGui>
class Test : public QDockWidget
{
Q_OBJECT
public:
Test (const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0) : QDockWidget (title, parent, flags)
{
}
protected:
void closeEvent (QCloseEvent *event)
{
printf ("closeEvent!\n");
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks