import os, os.path,sys
from qgis.core import *
from qgis.gui import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MapExplorer(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle("Landmark Explorer")
self.resize(800, 400)
def main():
QgsApplication.setPrefixPath(os.environ['QGIS_PREFIX'], True)
QgsApplication.initQgis()
app = QApplication(sys.argv)
window = MapExplorer()
window.show()
window.raise_()
app.exec_()
app.deleteLater()
QgsApplication.exitQgis()
if __name__ =="__main__":
main()
Then run this code and get:
Segmentation fault (core dumped)
What did I do wrong?
OpenSuse 42.2
Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Jan 4, 2017 at 19:18
2 Answers 2
You've got your initialisation the wrong way round. Try:
app = QgsApplication(sys.argv, True)
QgsApplication.setPrefixPath(os.environ['QGIS_PREFIX'], True)
QgsApplication.initQgis()
Note also the creation of a QgsApplication
, not a QApplication
.
You might still get a seg fault when the application exits because I don't think you've cleaned up properly, but my adjustment above should pop up your main window.
answered Jan 4, 2017 at 20:05
This worked:
app = QApplication(sys.argv)
QgsApplication.setPrefixPath(os.environ['QGIS_PREFIX'], True)
QgsApplication.initQgis()
lang-py