Geographic Information Systems Asked on May 22, 2021
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
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.
Correct answer by Spacedman on May 22, 2021
This worked:
app = QApplication(sys.argv)
QgsApplication.setPrefixPath(os.environ['QGIS_PREFIX'], True)
QgsApplication.initQgis()
Answered by nospec on May 22, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP