33 QT Creator Tips and Tricks
33 QT Creator Tips and Tricks
33 QT Creator Tips and Tricks
psychopath.
33
QT CREATOR
TIPS AND TRICKS
SHORTCUTS, COOL FEATURES AND MORE
BY DANIEL GAKWAYA
Founder and Lead Instructor at LearnQt Guide
Qt Creator is the defacto IDE for developing Qt applications. When you open a project with it, you see
something like below :
You can use it like average Joe by just clicking around and constantly hopping between your keyboard
and mouse to do stuff, which is fine when you're just getting started; but as you grow used to it, you start
requiring more speed and efficiency out of your Qt Creator workflow.
In this guide, I'm going to share with you some of the most interesting features of the
IDE that I use on a daily basis and find quite useful enough to share with you here.
Some are going to be shortcut combinations that can save you a few clicks and hand
moves from keyboard to mouse, others are just going to be useful features to navigate
and manipulate your code. The tips will be revolving around the 6 bubble boxes below :
Getting Help
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
General Usage & Navigation
Tip 1 Switching Qt Creator Modes
Qt Creator has 6 modes of operation. The modes are captured in the image shown on
the left. You can switch to your desired mode by clicking on it with the mouse. But that's
the slow way ! We can go faster by using a shortcut.
Hitting the Esc key at any time, brings you back to the Edit mode. Since this
Esc is where you'll spend most of your time in Qt Creator editing and crafting
your code, it makes sense to provide an even quicker way to get there.
I'm always going back and forth between Edit mode and Help mode. My hands have developed
muscle memory for Ctrl + 2 , Ctrl + 6 and the Esc key to hop back to Edit mode. I recommend
spending some time practicing these shortcuts and incorporate them in your workflow from
now on.
The tips and tricks shared in this booklet are best learnt by practicing each one at least for a
few minutes until you feel comfortable. And don't stop just there. Do your best to incorporate
in your daily workflow in Qt Creator. If it helps, you can print out this booklet and have it
somewhere close to you for ease of reference. Research suggests that 80 % of people will read
about these tricks and just forget about them the next day. Don't be one of them. OK, I made
that percentage up, but practice is still important.
Qt Creator has a bunch of output panes in the bottom part of its user interface.We use them to monitor
different aspects of our application.For example we can use the Issues pane to see build errors, the
Search Results pane to do search in our code, Application Output pane to see debug output, you get
the idea.As usual, you can change to your desired output pane by clicking with your left mouse, but we can
go faster by using short cuts.
The panes we use the most are the Issues Pane, Application Output Pane and the Compile
Output Pane. Because of that, I have developed muscle memory for Alt+1 , Alt+3 and Alt+4.
We recommend identifying the panes you'll likely use the most (3 or 4 will do) and practice the
shortcuts to jump back and forth between them now. And don't worry; you can always cheat a
bit by looking at the output panes in Qt Creator at the bottom, the number for each pane is
there for you to see.
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
General Usage & Navigation
Tip 3 Navigating through Open Documents
When you open a file to work on in Qt Creator, it will show up in the Open
Documents Widget.Sometimes you have too many of them opened and you
want to pick a particular file. You can scroll around and double click on your file
of interest, but that takes your hands away from the keyboard. There must be a
shortcut for this right?
Alt + < history log. One thing to note about the history log is that it
doesn't take into account the modifications you do to files. So if
you open a file and type in some text, the log will know that you
just opened the file. Nothing more. I do recommend trying this
Alt + > out and developing your own understanding of this history log.
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
General Usage & Navigation
Tip 6 Navigate to a Line Number
What do you do when you want to jump to a given line number in the file you're editing? Scroll your
way through potential thousands of lines of code? Naaah! There must be a better way.
You can also type in the line and column to precisely force the cursor at
a given line and column. Just use the format line:column. Line and
column information can be seen in the little widget in the top right
corner of Qt Creator.
Or, you can just hit the F4 key on your keyboard to achieve the
F4 same effect without taking your fingers off the keyboard.
Or, you can just hit the F2 key while hovering over the symbol (
F2 variable, class, method) of interest.
Let's add some juice to this tip by showing you that you can also
find usages for a symbol ( variable,class,method) in a project. You
can do that by right clicking and choosing Find References to
Symbol Under Cursor, or you can use a shortcut for that.
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
Help
Tip 9 Getting Help
What do you do when you want to browse the documentation for a variable, method, class,enum or anything
really ? Qt Creator makes this very easy by baking the entire documentation in for us to find what we want
without leaving the IDE (Integrated Development Environment). You already know that the Ctrl + 6 shortcut
throws us in Help Mode and from there we can index search whatever we want.
Index search !What's that ? Well it turns out in Help Mode, there are
different settings you can search using. Just hit on the drop down icon and
they will be laid down for you to see. I personally only use index because it
gives the information in any easy to understand manner (personal
preference), but you can try out the others and see what you like more. To
hop into help mode and index search, I use a combination of shortcuts.
Ctrl + 6 then
Ctrl + Shift + I
This allows me to quickly get to the point where I just type what I'm looking for without taking my hands
off the keyboard. The Ctrl + Shift + I shortcut forces us into index search regardless of the search
setting we were using. Sometimes you'll spot a symbol ( variable, method, class) or whatever really and
wonder what it is doing in your code. You can copy that and hop over in help mode and paste that in
the search line edit to index search; but that's too much work, we can do better.
This is better explained with a concrete example. Let's say I spot QGraphicsScene in my code and I want to
look that up in the Qt official documentation. All I have to do is hover over the symbol (I usually select for
better visibility) and hit the F1 key on your keyboard. This will open two windows one for code and the other
for the documentation as shown above. If you want to go in full help mode where the code is not shown,
you can click on the Open in Help Mode button to the top. But getting our fingers off the keyboard wastes
precious milliseconds! You can hit F1 again and you'll get the same effect.
The official Qt Documentation which is what is bundled into Qt Creator doesn't account for
standard C++ stuff. If you search for standard C++ keywords like switch for example the Qt
Doc is just going to throw you a sad message saying : No documentation available. Whey
you'll given such messages, it's better to search C++ specific reference documentations. A
good example is https://en.cppreference.com/w/ but I'm sure you can find more in your
favorite search engine
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
Manipulating Code
Tip 10 Selecting a Portion of Code
Now, what's there to say about selecting code in Qt
Creator? Well, on top of the good old mouse press
and drag selection, we can use a handy shortcut to
speed things up a bit.
I usually hold down Ctrl + Shift and hit > or < multiple times until the code I want selected is
fully selected. Try this a couple of times until you are comfortable.
Manipulating Code
Tip 11 Selecting a Block of Code
What is you want a faster way to select blocks of code, like what you
see on the screen capture to the right here? The Ctrl + U shortcut
will come in handy in this situation.
You start somewhere inside the block, for example inside the copy
method captured above, hold the Ctrl key down and hit the U key
Ctrl + U multiple times until you have your desired selection. If you keep
pressing U , you'll even get to the point where the entire file is
selected !
While we are here, it is also worth noting that you can jump
to the start of the block without selection using Ctrl + [ ,
and to the end of the block without selection with Ctrl + ] , [
this is just a quick way to position the cursor at a given Ctrl +
location. It actually easier to see if you try this yourself
rather than me talking about it. Try it out ! ]
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
Manipulating Code
Tip 12 Commenting Code Out
Want to comment a block of code out ? You can
go at it line by line putting in //'s in front of each
line, but there's a more civilized way doing this.
This shortcut will comment out any block of code you have
Ctrl + /
selected. Please note that what we use here is a forward
slash key. I have seen students confuse this with an
italicized i character. Don't be one of them .
This shortcut has a toggle feature: It will select the code block if it's not selected and will deselect
otherwise. This is a good chance to practice different ways we have seen to select code.
Remember Ctrl + Shift + (<,>) and Ctrl + U ? Try them out here and comment/uncomment
your selected code.
Manipulating Code
Tip 13 Indent Selected Code
Not much to say here, sometimes we just need to clean
up our code and make sure it is correctly and beautifully
indented for ease of reading. No need to worry , just Ctrl + I
select your code and use the shortcut.
Another chance to practice your code selection shortcuts. Select a piece of code and try to
indent that without taking your hands off the keyboard. I know , I know, they feel weird and
uncomfortable first but once to get comfortable, you'll wonder how you lived without them.
Manipulating Code
Tip 14 Trigger Code Completion
Code completion is one of the greatest
inventions in modern times IDEs in my opinion. I
not only use it to speed things up, but also to
learn about some methods available on my
objects without going browsing for help.
You can trigger code completion at any time Ctrl + Space
using the appropriate shortcut.
Manipulating Code
Tip 15 Trigger Quick Fix
Some times, your compiler will have an idea and suggest how to fix some problems in your code. When
you have warnings in your code, you might invite our compiler to give you hits on how to fix the problem
with the Alt + Return shortcut.
Will give you a hint. If you are happy with the hint, just
Alt + Return hit enter and it will be applied to your code.Return is
just the Enter Key on your keyboard.
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
Editing Code
Tip 16 Copy, Cut & Paste
Ctrl + C
I know , I know. Everybody uses these shortcuts
,but I wouldn't feel this guide is complete without
them mentioned. So here you go. Ctrl + C to
copy selected code, Ctrl + X to cut and Ctrl + V
Ctrl + X
to paste at the cursor position.
Ctrl + V
Now, something many of you may not know, is
that you can navigate through your clipboard
history and choose exactly what it is you want
pasted at the cursor position
Editing Code
Tip 17 Undo & Redo
Another very common action is to undo and
redo operations. Nothing more to say here,
Ctrl + Z
undo will cancel whatever operation you just did
+ Shift +
and redo will bring back what you had canceled
with undo. Ctrl Z
Editing Code
Tip 18 Select All . Copy & Cut Line
When you need to select everything in your file, this
shortcut will save you a move of the hands from the
keyboard to the mouse. I use it everyday especially
Ctrl + A when I want to automatically indent my code in the file
and I have developed muscle memory for Ctrl + A
followed by Ctrl + I .
Editing Code
Tip 20 Move line up & down
When in need of moving a line up or down in
my file, I used to just mouse select the line, cut
it, and paste it exactly where I want it. Notice Ctrl + Shift + Up
the hand move from keyboard to mouse? I was
very excited when I learnt about these
shortcuts. Try them out in Qt Creator to move Ctrl + Shift + Down
your line of choice up or down
Ctrl + Shift + Up
Sometimes you need to copy the line to the
previous line or the following line. In that case
just modify the shortcut a bit and you have
your copies. Try this out ! Ctrl + Shift + Down
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
Locator
Tip 23 Introducing the Locator
Locator is one of the most powerful features in Qt
Creator. You can use it to search and find stuff , run
commands and all kinds of crazy things. We are
going to just scratch the surface here but it's still
pretty cool. You'll see. When you invoke the locator
widget, it looks like the screen capture to the right.
But wait, how to we invoke it ?
Will pop up the locator widget as shown in the
+
screen capture above. It gives you hits on how to
Ctrl K use it right away with filters to do all kinds of crazy
things. Now, let's use it to do something.
Locator
Tip 24 Quickly Finding Files in Project
Locator
Tip 25 Jump to line : column in File
type l in the locator box then space
, then the line and column in format
Ctrl + K line:column. When done, hit Enter
and you'll be brought to that line
and column.
The l character in the locator command above is what we call a filter. Different filters
do different things. l allows us to target a line, m filters for methods, c filters for
classes etc. We're going to play with more filters from now on. For hints on filters, just
checkout the text on the locator widget when you have just hit Clrl + K.
Ctrl + K
method you're looking for. When
you've got what you're looking for,
hit Enter and you're brought to the
method in Qt Creator
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
Locator
Tip 27 Find a Class
Ctrl + K
class you're looking for. When
you've got what you're looking for,
hit Enter and you're brought to the
method in Qt Creator
You can use the : filter to either search for classes or methods. Try it out !
Locator
Tip 28 Find Methods in Current Document
Locator
Tip 29 Find Something in Qt Help Index
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
Locator
Tip 30 Web Search
+
to search for in your favorite web
Ctrl K engine. Hit Enter and your default
browser will open up with the
search results. Cool right ?
You can also use other search engines by using the UP and DOWN keys and
hitting Enter. It is possible add your own search engines in the settings. More on
that below.
Locator
Tip 31 Change Locator Settings
I hope by now you have realized that the locator is a gold mine of cool little
tips and tricks to really speed up how you do things in Qt Creator. If you
happen to need to tweak it to your own liking, just hit on the search like
icon to the left with your left mouse button and play around with the
options in the pop up menu.
More than often, you will need to search, find or replace stuff
in your code. In Qt Creator, you'll find the features for that in
the Edit -> Find & Replace menu. When Find & Replace is
invoked, a search widget in Qt Creator pops up to the bottom
allowing you to type what you're looking for and replacing
that with something else if you want that.The matches for
your search key are highlighted in yellow as seen in the
screen capture above. As seen to the right, Find & Replace
can also be invoked using a shortcut.
Will trigger the Search & Replace
feature and allow you to search for
Ctrl + F
things in the currently opened file.
You can use the provided buttons
to Replace, Replace All etc
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
You can navigate trough the results of Find & Replace either by using the Find Next and Find
Previous Buttons, or the respective shortcuts and keep your hands on the keyboard.
This brings us to the end of the Tips & Tricks I had to share with you in this little
booklet. We have seen a lot of shortcuts and it may take some time to get used
to most of them. You don't have to memorize them right now. Just try to
incorporate them into your daily workflow in Qt Creator.
To make the reference easy, I went ahead and summarized the features and
shortcuts in one page you can print and have with you next to your PC when
messing things up in Qt Creator. Head to the next page and check it out.
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/
Qt Creator Features and Shortcuts
The leading source for Qt related online video training resources: Qt,C++,QML and more.
See our courses : https://www.learnqt.guide/courses/