|
|
(130 intermediate revisions by 41 users not shown) |
Line 1: |
Line 1: |
| Your first program shall greet the world with a friendly "hello world", what else ? For that, we will use a KMessageBox. To get more information about the KMessageBox-Class, type "kde: kmessagebox" in your konqueror and it will redirect you to http://developer.kde.org/documentation/library/cvs-api/kdelibs-apidocs/kdeui/html/classKMessageBox.html
| | This [https://develop.kde.org/docs/getting-started/hello_world/ first program] page was move [https://develop.kde.org/docs/getting-started/hello_world/ here]. |
| <code cppqt n>
| |
| #include <QString>
| |
| #include <kapplication.h>
| |
| #include <kaboutdata.h>
| |
| #include <kmessagebox.h>
| |
| #include <kcmdlineargs.h>
| |
| | |
| int main (int argc, char *argv[])
| |
| {
| |
| KAboutData aboutData( "tutorial1", "Tutorial 2",
| |
| "1.0", "KMessageBox popup",
| |
| KAboutData::License_GPL, "(c) 2006" );
| |
| KCmdLineArgs::init( argc, argv, &aboutData );
| |
| KApplication app;
| |
| KGuiItem guiItem( QString( "Hello" ), QString(),
| |
| QString( "this is a tooltip" ),
| |
| QString( "this is whatsthis" ) );
| |
| KMessageBox::questionYesNo( 0, "text", "caption", guiItem );
| |
| }
| |
| </code>
| |
| If you set up your environment as described in [[Build/Unstable Version|Build/Unstable Version]], you can compile this code with
| |
|
| |
| gcc main.cpp -o tutorial1 -I/home/kde-devel/qt-unstable/include/Qt \
| |
| -I/home/kde-devel/qt-unstable/include/Qt-Core \
| |
| -I/home/kde-devel/qt-unstable/include -I/home/kde-devel/kde/include \
| |
| -L/home/kde-devel/kde/lib \
| |
| -L/home/kde-devel/qt-unstable/lib -lkdeui -lkdecore -ldl
| |
| and then run it with
| |
| ./tutorial1
| |
| | |
| If that worked, you may want to use cmake, just like the rest of KDE.
| |
| Create a file named CMakeLists.txt with this content:
| |
| <code>
| |
| #name of the project
| |
| project (tutorial1)
| |
| | |
| #find and use the necessary libraries and headers
| |
| find_package(KDE4 REQUIRED)
| |
| include_directories( ${KDE4_INCLUDES} )
| |
| | |
| # compile
| |
| # using a variable is not really necessary:
| |
| # using the single line
| |
| # kde4_add_executable(tutorial1 main.cpp)
| |
| # does the same, but when you add more stuff to the project,
| |
| # using the variable makes things a bit easier.
| |
| set(tutorial1_SRCS hello.cpp)
| |
| kde4_add_executable(tutorial1 ${helloSources})
| |
| | |
| # and link properly
| |
| target_link_libraries(tutorial1 ${KDE4_KDEUI_LIBS})
| |
| </code>
| |
| | |
| {{KDE4}}
| |