Development/Tutorials/Using Qt Creator: Difference between revisions

From KDE TechBase
m (Fix syntax highlighting.)
m (Reverted edits by Yurchor (talk) to last revision by Ochurlaud)
 
(26 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Template:I18n/Language Navigation Bar|Development/Tutorials/Using Qt Creator}}
{{Moved To Community | Guidelines_and_HOWTOs/Using_Qt_Creator}}
 
QtCreator is an IDE from Nokia for Qt. It contains QtDesigner for UI design. This article describes:
* how to create a new program
* how to load an existing program
 
= 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 [http://qt.nokia.com/doc/designer-manual.html user documentation].
 
;Step 0:
Call Qt Designer from within the [http://labs.trolltech.com/page/Projects/Tools/QtCreator QtCreator] [http://en.wikipedia.org/wiki/Integrated_development_environment IDE]:
<pre>
qtcreator
</pre>
 
;Step 1:
Add the widgets you want by drag-and-drop
 
[[File:Designer-step1.png|200px]]
 
;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.
 
[[File:Designer-step2.png|200px]]
 
;Step 3:
Select Form -> Lay Out in a <u>G</u>rid
 
[[File:Designer-step3.png|200px]]
 
;Result:
You get a decent look, and if you resize the window, the widgets resize as well.
 
[[File:Designer-result.png|200px]]
 
== 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
<pre>
LIBS += -lkdeui
</pre>
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:
<syntaxhighlight lang="cpp-qt">
ui->toolBar->addAction(QIcon("/usr/share/icons/oxygen/22x22/apps/ktip.png"),"hello world");
</syntaxhighlight>
[[Development/Tutorials/Using_Qt_Designer|More Info...]]
 
= Load an existing project =
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 [http://userbase.kde.org/ktimetracker ktimetracker] from the kdepim module, other applications should work analog.
 
You can either work with code on your disk or have QtCreator do the subversion checkout.
 
== use code from your disk ==
* 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"
 
== have QtCreator do the subversion checkout ==
* 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, so the local directory where the checkout will be loaded in
* 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"
 
== have QtCreator do the git checkout ==
* Choose File -> New File or Project -> Version Control -> Git Checkout.
* Enter a git URL like [email protected]:/kdepim
* accept kdepim as checkout directory
* 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"
 
== Run cmake ==
* Enter arguments for cmake like
<pre>
/root/kdepim -DCMAKE_INSTALL_PREFIX=/usr/local -DLIB_SUFFIX=64 -DCMAKE_BUILD_TYPE=debugfull
</pre>
<tt>DLIB_SUFFIX=64</tt> means that you want to install your libraries into directories named <tt>lib64</tt>, not <tt>lib</tt>. ''/root/kdepim'' is where your source code is.
* click "Run cmake"
* Note a .cbp file gets 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
 
= See also =
* [[Development/Tutorials/Using Qt Designer]]
* [[Getting_Started/Set_up_KDE_4_for_development#QtCreator]]
 
[[Category:KDE4]]

Latest revision as of 12:31, 9 February 2018

This page is now on the community wiki.