3
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

3

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
0
1

This worked:

app = QApplication(sys.argv)
QgsApplication.setPrefixPath(os.environ['QGIS_PREFIX'], True)
QgsApplication.initQgis()
answered Dec 22, 2020 at 5:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.