Difference between revisions of "Marble/MarbleCPlusPlus"

Jump to: navigation, search
Line 8: Line 8:
pre=[http://mindview.net/Books/TICPP/ThinkingInCPP2e.html C++], [http://www.trolltech.com/products/qt/ Qt]|
pre=[http://mindview.net/Books/TICPP/ThinkingInCPP2e.html C++], [http://www.trolltech.com/products/qt/ Qt]|
next=[[Editing Projects/Marble/MarbleGeoPainter|Tutorial 2 - Marble's GeoPainter]]|  
next=[[Projects/Marble/MarbleGeoPainter|Tutorial 2 - Marble's GeoPainter]]|  

Revision as of 22:23, 28 January 2010

Editing Projects/Marble/MarbleCPlusPlus

Hello Marble
Tutorial Series   Marble C++ Tutorial
Previous   C++, Qt
What's Next   Tutorial 2 - Marble's GeoPainter
Further Reading   n/a

Hello Marble!

The Marble API allows a very easy integration of a map widget into your application. Let's prove that with a tiny "Hello world"-like example:

  1. include <QtGui/QApplication>
  2. include <marble/MarbleWidget.h>

using namespace Marble;

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

   QApplication app(argc,argv);
   // Create a Marble QWidget without a parent
   MarbleWidget *mapWidget = new MarbleWidget();
   // Load the OpenStreetMap map
   return app.exec();


Save the code above as my_marble.cpp and compile it:

g++ -I /usr/include/qt4/ -o my_marble my_marble.cpp -lmarblewidget -lQtGui

If things go fine, execute ./my_marble and you end up with a fully usable OpenStreetMap application: My marble.png

Here's a little checklist to tackle some problems that might arise when compiling the code above:

  • You need Qt and Marble development packages (or comparable SVN installations)
  • If Qt headers are not installed in /usr/include/qt4 on your system, change the path in the g++ call above accordingly.
  • Likewise, add -I /path/to/marble/headers if they're not to be found in /usr/include

Content is available under Creative Commons License SA 4.0 unless otherwise noted.