I'm trying to develop an Standalone Application with Qt and QGIS API.

There are several code examples that should work, but they don't.

The Problem is that everytime I use "QgsApplication" the application Output says: "The program has unexpectedly finished."

Even this simple code does not work:

#include "mainwindow.h"
#include <QApplication>

#include "qgsapplication.h"

int main(int argc, char *argv[])
    QgsApplication app(argc, argv, true);

My Project.pro file:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Project

SOURCES += main.cpp\

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

LIBS += -L"C:/QGIS Building/lib" -lqgis_core -lqgis_gui

INCLUDEPATH += "C:/QGIS Building/include"

  • 1
    Have you tried a debugger? How are you linking this?
    – BradHards
    Commented Dec 16, 2014 at 20:59
  • No I haven't tried a Debugger yet. I added the linking to my question.
    – Niko
    Commented Dec 17, 2014 at 6:30
  • have you resolved this issue? Commented Nov 26, 2015 at 10:44
  • Yes I did. In my case it was just a bug in the QGis version I downloaded.
    – Niko
    Commented Nov 28, 2015 at 11:44
  • As June 2020 I have very similar question at: gis.stackexchange.com/questions/365057/… Commented Jun 16, 2020 at 14:40

1 Answer 1


I had similar problems, when I try to run a standalone QGis App. Important is that you call QApplication at first and then set context path for QGIS with

   QgsApplication::setPrefixPath("/usr", true);

(in LINUX) before you call.


A program initialisation that works for me looks like this.

 #include <QApplication>
 #include <qgsapplication.h>
 #include "mainwindow.h"

 int main(int argc, char *argv[]) {

   // 1. Initialize App
   QApplication app(argc, argv);
   QgsApplication::setPrefixPath("/usr", true);

    //2. App start
    MainWindow win(config, db);
    int result = app.exec();

    //3. Qgis free libs

    //4. And say goodby
    return result;
  • It's true what you say, it has to be coded in this order. But my Problem was a bug in the QGis Version, after I tried the latest version all my problems were gone.
    – Niko
    Commented Apr 14, 2015 at 14:22
  • sir how you are creating this application Like its simple visual studio project in which you are including qgis librarie? Commented Nov 26, 2015 at 11:15
  • I guess, the library declarion follows the qmake syntax en.wikipedia.org/wiki/Qmake, not visual studio configs.
    – huckfinn
    Commented Nov 30, 2015 at 22:45

Your Answer

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

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