Développement/Tutoriels/Utiliser Qt Creator

Jump to: navigation, search
Other languages:English 100% • ‎French 51%

Contents


Qt creator est un IDE développé par Nokia pour Qt. Il contient Qt designer pour le design d'Interfaces Utilisateur. Cet article décrit :

  • pourquoi utiliser Qt Creator
  • comment créer une nouvelle application
  • comment charger une application déjà existante

Pourquoi utiliser Qt Creator

KDE4's ktimetracker loaded as QtCreator project

To create your C++ applications you can use any text editor. But life will be much easier if you gain QtCreator's features. That means

  • you can get your source code saved, built and run with one click
  • you get code-completion
  • you can find all places in your source code where you call a function (e.g. "where do I call refresh()")
  • you can go back to a more recent cursor position with your editor, even if this is in another file
  • you can checkout and commit to Subversion or Git repositories without leaving your workflow

Créer un nouveau programme

Here is a short example of how you can create a "hello world" application. For more information read the user documentation.

Étape 0

Lancer QtCreator

qtcreator

Puis sélectionnez Nouveau fichier ou projet -> Applications -> Application graphique Qt -> Nom = helloworld -> Suivant -> Suivant -> Terminer

Step 1

Select Edit -> Forms -> mainwindow.ui. Add the widgets you want by drag-and-drop:

Designer-step1.png

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.

Designer-step2.png

Step 3

Select Form -> Lay Out in a Grid

Designer-step3.png

Résultat

Vous obtenez un aspect convenable , et si vous redimensionnez la fenêtre, les widgets seront redimensionnés aussi.

Designer-result.png

Utiliser les librairies KDE

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

LIBS += -lkdeui

Then you can start using KDE classes in your code.

Ajouter une barre d'outils

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...

Charger un projet existant

This describes how to use QtCreator to integrate existing 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 should work likewise.

You can either work with code on your disk or have QtCreator do the repository checkout.

Utiliser un code local

  • import the CMakeLists.txt file (File -> Open -> kdepim/CMakeLists.txt)
  • as build directory choose kdepim
  • you will automatically come to a screen where you can run CMake
  • continue with the step "Run cmake"

Utiliser QtCreator pour faire un checkout d'un dépôt Git

  • choose File -> New File or Project -> Project from Version Control -> Git Repository Clone.
  • enter a Git URL like git@git.kde.org:/kdepim
  • accept kdepim as checkout directory
  • type finish, see how the checkout starts
noframe
 
Note
If the checkout fails with the message "remote host hung up unexpectedly" do a checkout from konsole. You may have to accept git.kde.org's fingerprint.
  • you will automatically come to a screen where you can run CMake
  • continue with the step "Run cmake"

Utiliser QtCreator pour faire un checkout d'un dépôt subversion

  • choose File -> New File or Project -> Version Control -> Subversion Checkout.
  • enter a Subversion URL like svn://anonsvn.kde.org/home/kde/trunk/KDE/kdepim
  • enter a checkout directory, i.e. the local directory where the code will be checked-out to
  • type finish, see how the checkout starts
  • you will automatically come to a screen where you can run CMake
  • continue with the step "Run cmake"

Lancer cmake

  • enter arguments for CMake like
/root/kdepim -DCMAKE_INSTALL_PREFIX=/usr/local -DLIB_SUFFIX=64 -DCMAKE_BUILD_TYPE=debugfull

DLIB_SUFFIX=64 means that you want to install your libraries into directories named lib64, not lib. /root/kdepim is where your source code is.

  • click "Run cmake"
  • note: a .cbp file is created containing many information about the build
  • click "Finish"

Build it

  • configure QtCreator to build only ktimetracker:

Projects -> Active run configuration=ktimetracker -> build settings -> build steps -> make -> show details -> activate ktimetracker.

  • configure QtCreator to use 8 logical processors:

Projects -> Active run configuration=ktimetracker -> build settings -> build steps -> make -> show details -> addtional Arguments = -j8

  • choose Build -> Build All

Voir aussi


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal