This page is about using Marble in your project. Looking for information on contributing to Marble instead? Learn more »

The Marble library is written in C++ and provides bindings for Qt Quick (QML). Below you find some examples that demonstrate a basic integration of a map widget provided by Marble into custom C++ and QML applications. You might also be interested to learn about

Integrating Marble in your C++ project is as simple as creating and using an instance of Marble::MarbleWidget. Here's a basic application:

#include <QApplication>
#include <marble/MarbleWidget.h>

int main(int argc, char** argv)
{
    QApplication app(argc, argv);

    // Load Marble using OpenStreetMap in Mercator projection
    Marble::MarbleWidget *mapWidget = new Marble::MarbleWidget;
    mapWidget->setProjection(Marble::Mercator);
    mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");

    mapWidget->setWindowTitle("Hello Marble!");
    mapWidget->show();
    return app.exec();
}

Compile the code with your favorite build system, linking against Qt5 and Marble (no need to link against any KF5 libraries):

An appropriate CMakeLists.txt file to build the sample code above (saved to the file main.cpp) using CMake looks like this:

cmake_minimum_required(VERSION 2.8.12)

project(hello-marble)

find_package(Qt5Widgets REQUIRED)
find_package(Marble REQUIRED)

add_executable(hello-marble  main.cpp)
target_link_libraries(hello-marble  Marble Qt5::Widgets)

With those two files created you can compile and run the sample application by:

cmake .
make
./hello-marble

An appropriate hello-marble.pro file to build the sample code above (saved to the file main.cpp) using qmake looks like this:

TEMPLATE = app

CONFIG += qt

QT += Marble

SOURCES += \
  main.cpp

With those two files created you can compile and run the sample application by:

qmake hello-marble.pro # or qmake-qt5
make
./hello-marble

For qmake to know about the Marble module, you have to do one out of these:

  • install Marble into the same prefix as your Qt5 installation (e.g. /usr)
  • pass -DMARBLE_PRI_INSTALL_USE_QT_SYS_PATHS=ON to cmake when building Marble
  • use the environment variable QMAKEPATH to point to the installation prefix of Marble when calling qmake hello-marble.pro

Further examples can be found in a set of C++ tutorials in KDE Techbase. They are also part of the Marble sources in the examples/cpp/ path.

Thanks to our QtQuick integration you can use Marble in QML projects. A basic Marble QML application looks like this:

import QtQuick 2.1
import org.kde.marble 0.20

MarbleWidget {
  projection: "Mercator"
  mapThemeId: "earth/openstreetmap/openstreetmap.dgml"
}

Further examples can be found in the Marble sources in the examples/qml/ path.


KDE