Because you don't instantiate the member QPainter.
You have two options:
1. Add:
Qt Code:
  1. painter = new QPainter();
To copy to clipboard, switch view to plain text mode 
in the constructor, and:
Qt Code:
  1. delete painter;
To copy to clipboard, switch view to plain text mode 
in the destructor.

2. Remove the member( recommended ) and in paint event:
Qt Code:
  1. QPainter painter(this);
  2. painter.drawPolygon(polygoon);
To copy to clipboard, switch view to plain text mode 

Regards