Development/Tutorials/Using Qt Creator

From KDE TechBase
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


Development/Tutorials/Using Qt Creator


QtCreator is an IDE from Nokia for Qt. It contains QtDesigner for UI design.

Creating a new program

Qt Designer is a graphical program which allows you to easily build user interfaces, using a drag n drop interface. Here is a short example how it can go, for more information read the user documentation.

Step 0

Call Qt Designer from within the QtCreator IDE:

qtcreator
Step 1

Add the widgets you want by drag-and-drop

Step 2

Select the mainwindow. This is the one un-intuitive step. To lay out the objects in the mainwindow, you do not select the objects in the mainwindow, but the mainwindow itself.

Step 3

Select Form -> Lay Out in a Grid

Result

You get a decent look, and if you resize the window, the widgets resize as well.

Using KDE libraries

To use KDE classes like KMessageBox, you need to tell qtcreator to use the KDE libraries when building. Go to your home directory, cd into yourproject and modify yourproject.pro. Add a line

LIBS += -lkdeui

Then you can start using KDE classes in your code.

Adding a toolbar

To add a toolbar, right-click on the UI and choose "Add Toolbar". Then you can set icons and text in your mainwindow's constructor with code like this:

ui->toolBar->addAction(QIcon("/usr/share/icons/oxygen/22x22/apps/ktip.png"),"hello world");

More Info...

Load an existing project

This describes how to use QtCreator to develop KDE 4 applications. It has been tested with QtCreator 1.2.80 and SUSE Linux 11.1 but should work same or similar with every combination. As an example KDE application we use ktimetracker from the kdepim module, other applications short work analog.

  • Import the CMakeLists.txt file

File -> Open -> kdepim/CMakeLists.txt.

  • Configure qtcreator to build only ktimetracker

Projects -> ktimetracker -> build settings -> Add a configuration ktimetracker.

As build directory choose /home/youruser/kdepim/ktimetracker. As arguments for cmake use ...


See also