Marble/MarbleCPlusPlus: Difference between revisions
Earthwings (talk | contribs) m svn => git |
Earthwings (talk | contribs) Fix code formatting |
||
Line 19: | Line 19: | ||
[http://www.openstreetmap.org OpenStreetMap]. Then we call [http://doc.trolltech.com/qwidget.html#show QWidget::show()] to show the map widget and we call [http://doc.trolltech.com/qapplication.html#exec QApplication::exec()] to start the application's event loop. That's all! | [http://www.openstreetmap.org OpenStreetMap]. Then we call [http://doc.trolltech.com/qwidget.html#show QWidget::show()] to show the map widget and we call [http://doc.trolltech.com/qapplication.html#exec QApplication::exec()] to start the application's event loop. That's all! | ||
< | <source lang="cpp-qt"> | ||
#include <QtGui/QApplication> | #include <QtGui/QApplication> | ||
#include <marble/MarbleWidget.h> | #include <marble/MarbleWidget.h> | ||
Line 40: | Line 39: | ||
return app.exec(); | return app.exec(); | ||
} | } | ||
</source> | |||
Copy and paste the code above into a text editor. Then save it as <tt>my_marble.cpp</tt> and compile it by entering the following command on the command line: | |||
Copy and paste the code above into a text editor. Then save it as <tt>my_marble.cpp</tt> and compile it by entering the | |||
< | <source lang="bash"> | ||
g++ -I /usr/include/qt4/ -o my_marble my_marble.cpp -lmarblewidget -lQtGui | g++ -I /usr/include/qt4/ -o my_marble my_marble.cpp -lmarblewidget -lQtGui | ||
</ | </source> | ||
If things go fine, execute <tt>./my_marble</tt> and you end up with a fully usable OpenStreetMap application: | If things go fine, execute <tt>./my_marble</tt> and you end up with a fully usable OpenStreetMap application: |
Revision as of 20:43, 26 June 2011
Editing Projects/Marble/MarbleCPlusPlus
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
Tutorial Series | Marble C++ Tutorial |
Previous | C++, Qt |
What's Next | Tutorial 2 - MarbleWidget: Changing basic map properties |
Further Reading | n/a |
Hello Marble!
The API of the Marble library allows for a very easy integration of a map widget into your application.
Let's prove that with a tiny Hello world-like example: Qt beginners might want to have a look at the Qt Widgets Tutorial to learn more about the details of the code. But this is probably not necessary. For a start we just create a QApplication object and a MarbleWidget object which serves as a window. By default the MarbleWidget uses the Atlas map theme. However for our first example we choose to display streets. So we set the maptheme id to OpenStreetMap. Then we call QWidget::show() to show the map widget and we call QApplication::exec() to start the application's event loop. That's all!
#include <QtGui/QApplication>
#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
mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
mapWidget->show();
return app.exec();
}
Copy and paste the code above into a text editor. Then save it as my_marble.cpp and compile it by entering the following command on the command line:
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:
- You need Qt and Marble development packages (or comparable git 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