2
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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.