KDE TechBase
  • Page
  • Discussion
  • Edit
  • History
KDE TechBase is a Wiki - You can help! Please contribute! Questions?

Development/Tutorials/Programming Tutorial KDE 4/Start your CMAKE project

< Development | Tutorials | Programming Tutorial KDE 4
Warning
noframe
This page has been nominated for speedy deletion. This delay is intended to give the contributor time to modify the page to make it relevant. If it is relevant, please remove this tag.

If you disagree with its speedy deletion, remove the template and discuss it on its talk page.

Administrators: Please check the page history, especially the last diff, and What links here before deleting.


Warning
noframe
This isn't really a tutorial. Almost everything in here is covered by the beginner's tutorial series anyway. I recommend this be removed at some point.


To start a KDE 4 project is more than starting a program - you have to deliver the build environment as well. This article shows you how to start a project with KDE 4 and CMake. As a first step, we create a simple but friendly program - it shows you a button and a label. If you click the button, the label greets you with "hello".

Contents

  • 1 Here we go
  • 2 Build it
  • 3 TroubleShooting
  • 4 Suggested Readings
  • 5 Thanks to

[edit] Here we go

We will call our project kde4start. Set up your KDE 4 environment as described at Getting_Started/Build/KDE4. Create a directory kde4start and cd into it:

mkdir kde4start
cd kde4start


Run designer to start the Qt designer, and chose to create a widget. You'll probably always want to create a widget. The other options in designer are for Qt only apps. Add a label called label and a pushButton called pushButton to the widget. Name the widget Kde4StartUi and save it as Kde4StartUi.ui

Create a Kde4Start.h file as so:

#ifndef KDE4START_H__
#define KDE4START_H__
 
#include <kmainwindow.h>
 
class Ui_Kde4StartUi;
class Kde4Start : public QWidget
{
  Q_OBJECT
  public:
    Kde4Start();
  public slots:
    void slotButtonClicked();
  private:
    Ui_Kde4StartUi *mKde4StartUi;
};
#endif

Create a Kde4Start.cpp as so:

#include "Kde4Start.h"
#include "Kde4Start.moc"
#include "ui_Kde4StartUi.h"
 
Kde4Start::Kde4Start() : QWidget(NULL)
{
  mKde4StartUi = new Ui_Kde4StartUi();
  mKde4StartUi->setupUi(this);
  connect(mKde4StartUi->pushButton, SIGNAL(clicked()),SLOT(slotButtonClicked()));
}
void Kde4Start::slotButtonClicked() {
  mKde4StartUi->label->setText("Hello");
}

Write your main.cpp:

#include <QString>
#include <kapplication.h>
#include <kaboutdata.h>
#include <kmessagebox.h>
#include <kcmdlineargs.h>
#include <KMainWindow>
#include "Kde4Start.h" 
 
int main (int argc, char *argv[])
{
  KAboutData aboutData( "test", "test",
      "1.0", "test", KAboutData::License_GPL,
      "(c) 2006" );
  KCmdLineArgs::init( argc, argv, &aboutData );
  KApplication khello;
 
  Kde4Start *mw = new Kde4Start();
  mw->show();
  khello.exec();
}

Write your CMakeLists.txt:

PROJECT( kde4start )
FIND_PACKAGE(KDE4 REQUIRED)
INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} . )
 
 
SET(kde4startSources main.cpp Kde4Start.cpp )
 
kde4_add_ui_files( kde4startSources Kde4StartUi.ui)
 
KDE4_ADD_EXECUTABLE(kde4start ${kde4startSources} )
 
TARGET_LINK_LIBRARIES(kde4start ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} )
 
install(TARGETS kde4start  DESTINATION ${BIN_INSTALL_DIR} )

[edit] Build it

To build and to run it do:

cmake . -DCMAKE_INSTALL_PREFIX=$KDEDIR \
               -DCMAKE_BUILD_TYPE=debugfull && \
make && make install
./kde4start

[edit] TroubleShooting

You can find out the actual values cmake found by looking into CMakeCache.txt.

[edit] Suggested Readings

  • KDE CMake Intro
  • http://www.cmake.org/Wiki/CMake

[edit] Thanks to

JohnFlux

Retrieved from "http://techbase.kde.org/Development/Tutorials/Programming_Tutorial_KDE_4/Start_your_CMAKE_project"

Category: Marked for Deletion

Navigation

  • Home
  • Help
  • Recent changes

Sections

  • Getting started
  • Development
  • Schedules
  • Policies
  • Contribute
  • Projects

Toolbox

  • What links here
  • Related changes
  • Upload file
  • Special pages
  • Printable version
  • Permanent link

Personal tools

  • Log in / create account
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. Qt® and Trolltech® are registered trademarks of Trolltech ASA. Linux® is a registered Trademark of Linus Torvalds. | Legal