More

Can't get my QGIS external map to display on Ubuntu trusty: QObject::connect: Cannot connect (null) error

Can't get my QGIS external map to display on Ubuntu trusty: QObject::connect: Cannot connect (null) error


I've been following along the examples from the book "Building Mapping Applications with QGIS and for the life of me I can't figure out why my shapefiles aren't loading and displaying in the app window under a Ubuntu system. The same code runs fine with my Macbook Pro setup.

I use a run.sh file to set up the linux environment:

export PYTHONPATH="/usr/share/qgis/python" export LD_LIBRARY_path="/usr/share/qgis/lib" export QGIS_PREFIX="/usr/share/qgis" python externalApp.py

I have tested that I can import all qgis, qgis.core, qgis.gui etc files without errors in Python.

The Linux script I'm using is pasted below. I have played around with the shapefile name and location.

import sys import os from qgis.core import * from qgis.gui import * from PyQt4.QtGui import * from PyQt4.QtCore import Qt ############################################################################# class MapViewer(QMainWindow): def __init__(self, shapefile): QMainWindow.__init__(self) self.setWindowTitle("Map Viewer") canvas = QgsMapCanvas() canvas.useImageToRender(False) canvas.setCanvasColor(Qt.white) canvas.show() layer = QgsVectorLayer(shapefile, "layer1", "ogr") #if not layer.isValid(): # raise IOError("Invalid shapefile") QgsMapLayerRegistry.instance().addMapLayer(layer) canvas.setExtent(layer.extent()) canvas.setLayerSet([QgsMapCanvasLayer(layer)]) layout = QVBoxLayout() layout.addWidget(canvas) contents = QWidget() contents.setLayout(layout) self.setCentralWidget(contents) ############################################################################# def main(): """ Our main program. """ QgsApplication.setPrefixPath(os.environ['QGIS_PREFIX'], True) QgsApplication.initQgis() app = QApplication(sys.argv) viewer = MapViewer("/home/cary/workspace/temp/alaska.shp") viewer.show() app.exec_() QgsApplication.exitQgis() ############################################################################# if __name__ == "__main__": main()

Computers used: 1) Toshiba Satellite windows machine, reconfigured with ubuntu 14.04 2) Macbook Pro computer

The Toshiba Satellite machine was a new machine and newly configured with Ubuntu. I basically just installed Ubuntu then updated the system and then installed QGIS with this script:

sudo sh -c 'echo "deb http://qgis.org/debian trusty main" >> /etc/apt/sources.list' sudo sh -c 'echo "deb-src http://qgis.org/debian trusty main" >> /etc/apt/sources.list' gpg --keyserver keyserver.ubuntu.com --recv 47765B75 gpg --export --armor 47765B75 | sudo apt-key add - sudo apt-get update && sudo apt-get install qgis python-qgis

Setup for both computers: Both computers are using Python 2.7.6

Standard setups for both of the machines. I pretty much just ran the script above for the Linux box.

Verified that the "/usr/share/qgis" folders were setup in Linux properly Verified that the structures on the Mac all matched up with the description of folders and contents from the book on page 21 for setting up PYTHONPATH, QGIS_PREFIX etc…

The Linux file structures were different: in the book: PYTHONPATH="/usr/share/qgis/build/output/python/" while I noticed on my system that the "/build/output/" directories were missing.

The same code worked on the Mac setup but not the Linux setup. I also verified that the path to the shapefiles were correct for the linux system.

Fortunately the Mac setup works and I can continue with the rest of the tutorial on that box but I would love to know why the Ubuntu box doesn't work.


I have tested your code on my Ubuntu-based computer, the only strange thing I see is a QGIS prefix that doesn't work for the common QGIS installation on GNU/Linux.

Try changing your QGIS_PREFIX variable to"/usr". The QGIS prefix is where QGIS can start to look for data providers and other resources (see Failed to create memory layers in QGIS application on Linux for details). In fact, by using your QGIS_PREFIX I also get an empty frame.


Watch the video: Solved Error Could Not Access Network Location Problem