title: QPixmap: Must construct a QApplication before a QPaintDevice
body: <p>I have a code which works in python console of QGIS. I am trying to work in an IDE but it does not work. I have changed it in different ways but it still returns:</p>
  
  <pre><code>QPixmap: Must construct a QApplication before a QPaintDevice
  </code></pre>
  
  <p>my code is:</p>
  
  <pre><code>import processing
  from qgis.core import*
  from PyQt4.QtCore import *
  import math
  from collections import defaultdict
  from shapely.geometry import LineString
  import json
  import datetime
  import time
  import itertools
  import glob
  import sys
  from nltk import metrics
  
  Class matching():
      def __init__(self):
  
          self.layers = []
  
          self.Dir_OSM_roads="D:/PhD works/PhD things/Julian/Matching_data/InputData/SHP/OSM_roads_no_psv_latin1_id.shp"    
  
      def laodLayer(self):
          self.layers[0]=QgsVectorLayer(self.Dir_OSM_roads,"test" , "ogr")
          QgsMapLayerRegistry.instance().addMapLayer(self.layers[0]);
          print self.layers[0]
  
      def printValidity(self):
          if not self.layers[0].isValid():
              print "layer does not exist"
          else:
              print "successful"
  
  def main():
      app = QApplication([],True)
  
      qgis_prefix = "C:/Program Files (x86)/QGIS Valmiera/apps/qgis"
  
      QgsApplication.setPrefixPath(qgis_prefix, True)
      QgsApplication.initQgis()
  
      check=matching()
      check.laodLayer()
      check.printValidity()
  
      retval = app.exec_()
  
      QgsApplication.exitQgis()
      sys.exit(retval)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>I am working in windows 7, 64 with aptana and QGIS 2.2.</p>
  
  <p>Edit: My windows is 64-bite</p>