Qt3 C++ Tutorial
Qt3 C++ Tutorial
First, you have to install the following packages by the following command
aptget install qt3designer qt3assistant qt3devtools qt3doc libqt3compatheaders g++ gcc
make makedev
Note: If you install more than one qmake & uic then run the two commands given below for
choosing correct one.
#updatealternatives config qmake
#updatealternatives config uic
In Ubuntu 8.04, it lies under Programming.
QT Designer will come up. It looks like this.
Double-click on the button on the canvas. A dialog will come up where you can
change the text displayed on the button. Let's rename it to Clear. Then click OK.
Here's the tricky part. After selecting the tool, click on your Clear button on the
canvas, and drag the mouse (without releasing) to your listbox on the canvas. Once
you are over the listbox (it will be highlighted), you will see a line from the button to
the listbox, and you can release the mouse. Another dialog box will pop up where
you can specify exactly which signal and slot you want to connect. Select
pushButton1 as the sender, clicked() as the signal, listBox1 as the receiver and
clear() as the slot. Then click OK. (The meaning of this is that we want to delete all
contents of the box when the user clicks the button.)
A dialog listing custom slots will show up. Initially, it will be empty. Let's add a new
slot by clicking New Function. Let's call this function AddEntry() (don't forget the
parentheses when typing in the new name) because it will add a new item to the list
box. Don't change any other settings and just click OK. (We'll write the code for this
method later on.)
Almost done! Last thing we need to do is to turn off the autoDefault setting for our
delete button. (Setting a button as default means that it will get 'clicked' if the user
presses Enter on the dialog. For us it would not make sense to add text to the list
box on Enter, and then have the delete button automatically triggered, clearing our
list box.) The autoDefault property is True by default, so we need to set it to False in
the Property Editor window for the button. Click on the button to see the Property
window for it in the lower right-hand corner.
#include <qapplication.h>
#include "form1.h"
Now open up a shell. We want to make a project file. Enter the following command
to make a project file.
#qmake –project
#qmake form1.pro
#make.
If you type something into the line edit box and press Enter, it should get added to
the list box. If you hit the Clear button, the list box should be cleared. If it doesn't
behave as it should, go back and re-read the steps, you probably missed something.
:)