QPixmap:必须在QPaintDevice之前构造QApplication

时间:2014-05-22 07:49:27

标签: python qgis qpixmap qapplication

我有一个在QGIS的python控制台中运行的代码。我正在尝试在IDE中工作,但它不起作用。我已经以不同的方式改变了它,但它仍然会返回:

QPixmap: Must construct a QApplication before a QPaintDevice

我的代码是:

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()

我正在使用aptana和QGIS 2.2在Windows 7,64中工作。

编辑:我的窗口是64位

0 个答案:

没有答案