Marble/MarbleCPlusPlus: Difference between revisions
Appearance
< Marble
No edit summary |
Better layout |
||
Line 3: | Line 3: | ||
<code cppqt> | <code cppqt> | ||
#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"); | |||
// Set a server for downloading map data, if needed | |||
mapWidget->setDownloadUrl("http://download.kde.org/apps/marble/"); | |||
mapWidget->show(); | |||
return app.exec(); | |||
} | |||
</code> | </code> | ||
Save the code above as <tt>my_marble.cpp</tt> and compile it: | Save the code above as <tt>my_marble.cpp</tt> and compile it: | ||
<code> | |||
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 | ||
</code> | |||
If things go fine, execute <tt>./my_marble</tt> and you end up with a fully usable OpenStreetMap application: [[Image:My_marble.png]] | If things go fine, execute <tt>./my_marble</tt> and you end up with a fully usable OpenStreetMap application: [[Image:My_marble.png]] | ||
Here's a little checklist to tackle some problems that might arise when compiling the code above: | 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) | * You need Qt and Marble development packages (or comparable SVN installations) | ||
* If you're running Marble from SVN, add the Marble:: prefix to the MarbleWidget above. The Marble namespace was added some time ago. | * If you're running Marble from SVN, add the Marble:: prefix to the MarbleWidget above. The Marble namespace was added some time ago. | ||
* If Qt headers are not installed in /usr/include/qt4 on your system, change the path in the g++ call above accordingly. | * 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 | * Likewise, add -I /path/to/marble/headers if they're not to be found in /usr/include |
Revision as of 08:07, 9 February 2009
Hello Marble!
The Marble API allows a very easy integration of a map widget in your application. Let's prove that with a tiny "Hello world"-like example:
- 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");
// Set a server for downloading map data, if needed
mapWidget->setDownloadUrl("http://download.kde.org/apps/marble/");
mapWidget->show();
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:
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 you're running Marble from SVN, add the Marble:: prefix to the MarbleWidget above. The Marble namespace was added some time ago.
- 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