8/20/2019 Qt Basics GKO 2010
1/66
Qt basics
Tarmo Aidantausta, Digia Plc
8/20/2019 Qt Basics GKO 2010
2/66
2 © 2010 Digia Plc
Qt basics: About me
• I'm a Noia !erti"ied Qt De#elo$er%
• I &a#e around ear o" e($erience )it& it%
• I can read, co$, $aste and mae lists%
8/20/2019 Qt Basics GKO 2010
3/66
* © 2010 Digia Plc
Qt basics: +#er#ie)
• Presentation co#ers onl basics o" Qt and sim$lecom$onent and gra$&ics $rogramming%
• &at is Qt-
• &at can ou do )it& it-• !an I do console a$$lications-
• !an I do gra$&ical user inter"aces-
• & )ould I )ant to use it-
• &at do I need to no) to use it-
8/20/2019 Qt Basics GKO 2010
4/66
. © 2010 Digia Plc
Qt basics: +#er#ie)
• &at are t&e "undamentals o" Qt-
• /o) do I do I a$$lications )it& it-• /o) do I do /ello orld-
• /o) do I do e#ents-
• /o) do I do com$onents-
• 3ost o" t&e in"ormation &as been gat&ered and somee#en 4ust 5uoted as is "rom &tt$:665t%noia%com6doc6 %
8/20/2019 Qt Basics GKO 2010
5/66
7 © 2010 Digia Plc
&at is Qt-
• Qt is a cross8$lat"orm a$$licationand I "rame)or%
• sing Qt, ou can )ritea$$lications once and de$lot&em across desto$, mobile and
embedded o$erating sstems)it&out re)riting t&e source code%
• Qt is $artl !99 and $artl nati#ecode de$ending on $lat"orm%
• Qt I APIs )ra$ nati#e I
com$onents%
HW
Windows Kernel Mac Kernel
Win32 GDI Carbon / Cocoa
Qt/Windows Qt/Mac
Linux Kernel
X11
Qt/nix
Qt
Qt !"Is
!##lication 1 !##lication 2 !##lication 3
8/20/2019 Qt Basics GKO 2010
6/66
© 2010 Digia Plc
&at is Qt-
• +""icial su$$ort• ;mbedded
• indo)s
• 11
• indo)s !;
•
=0• 3eeo
8/20/2019 Qt Basics GKO 2010
7/66
? © 2010 Digia Plc
&at is Qt-
• According to ii$edia@ &tt$:66en%)ii$edia%org6)ii6Qt@toolitB B t&ere's bindings to Qt "rom:
• Pt&on• P=ide @
8/20/2019 Qt Basics GKO 2010
8/66
H © 2010 Digia Plc
&at can ou do )it& it-
• ou can do ant&ing )it& it%
• T&ere's $lent o" stu""%
8/20/2019 Qt Basics GKO 2010
9/66
J © 2010 Digia Plc
!an I do console a$$lications-
• es, ou can%
• Qt!ore &tt$:665t%noia%com6doc65tcore%&tml• T&e Qt!ore module contains core non8I "unctionalit%
• Q!oreA$$lication 8 ;#ent loo$ "or console Qt a$$lications
• &tt$:66doc%trolltec&%com65corea$$lication%&tml
• QtNet)or &tt$:665t%noia%com6doc65tnet)or%&tml• T&e QtNet)or module o""ers classes t&at allo) ou to
)rite T!P6IP clients and ser#ers%
http://qt.nokia.com/doc/qtcore.htmlhttp://doc.trolltech.com/qcoreapplication.htmlhttp://qt.nokia.com/doc/qtnetwork.htmlhttp://qt.nokia.com/doc/qtnetwork.htmlhttp://doc.trolltech.com/qcoreapplication.htmlhttp://qt.nokia.com/doc/qtcore.html
8/20/2019 Qt Basics GKO 2010
10/66
10 © 2010 Digia Plc
!an I do console a$$lications-
• Qt>ml &tt$:665t%noia%com6doc65t(ml%&tml• T&e Qt>ml module $ro#ides a stream reader and )riter
"or >3< documents, and !99 im$lementations o" =A>and D+3%
•
Qt>3
8/20/2019 Qt Basics GKO 2010
11/66
11 © 2010 Digia Plc
!an I do gra$&ical user inter"aces-
• +" course ou can%
• %%%multi$le )as
• ou can use all t&e $re#iousl mentioned non8I modules%
• T&ese are some o" t&e )idgets "rom t&e Qtui module:•
&tt$:665t%noia%com6doc6galler%&tml• /ere are all t&e classes under Qtui module:
• &tt$:665t%noia%com6doc65tgui%&tml
• ou can e#en do *D gra$&ics )it& it:• Qt+$en< &tt$:665t%noia%com6doc65to$engl%&tml
• T&e Qt+$en< module o""ers classes t&at mae it eas to use+$en< in Qt a$$lications%
• ;(am$les can be "ound "rom: &tt$:665t%noia%com6doc6e(am$les%&tmlEo$engl
http://qt.nokia.com/doc/gallery.htmlhttp://qt.nokia.com/doc/qtgui.htmlhttp://qt.nokia.com/doc/qtopengl.htmlhttp://qt.nokia.com/doc/examples.htmlhttp://qt.nokia.com/doc/examples.htmlhttp://qt.nokia.com/doc/examples.htmlhttp://qt.nokia.com/doc/examples.htmlhttp://qt.nokia.com/doc/qtopengl.htmlhttp://qt.nokia.com/doc/qtgui.htmlhttp://qt.nokia.com/doc/gallery.html
8/20/2019 Qt Basics GKO 2010
12/66
12 © 2010 Digia Plc
!an I do gra$&ical user inter"aces
• T&ere's e#en a )eb bro)ser ou can embed into oura$$lication:
• Qtebit &tt$:665t%noia%com6doc65t)ebit%&tml
• QtebKit $ro#ides a )eb bro)ser engine t&at maes iteas to embed content "rom t&e orld ide eb intoour Qt a$$lication%
• &tt$:665t%noia%com6doc6e(am$les%&tmlE)ebit
• Qt=#g &tt$:665t%noia%com6doc65ts#g%&tml• T&e Qt=#g module $ro#ides classes "or dis$laing t&e
contents o" =L "iles%
http://qt.nokia.com/doc/qtwebkit.htmlhttp://qt.nokia.com/doc/examples.htmlhttp://qt.nokia.com/doc/qtsvg.htmlhttp://qt.nokia.com/doc/qtsvg.htmlhttp://qt.nokia.com/doc/qtsvg.htmlhttp://qt.nokia.com/doc/examples.htmlhttp://qt.nokia.com/doc/examples.htmlhttp://qt.nokia.com/doc/qtwebkit.htmlhttp://qt.nokia.com/doc/qtwebkit.html
8/20/2019 Qt Basics GKO 2010
13/66
1* © 2010 Digia Plc
& )ould I )ant to use it-
• ou are a NERD and )ant to s&o) o"" our gra$&ical$rogramming sills-
• Qt &as a 5uite good $enetration on di""erent $lat"orms%
• It's "airl straig&t8"or)ard to $ort our a$$lication to
$lat"orms )&ere Qt is su$$orted%• Qt &as been around "or a long time, so it &as matured as a
"rame)or%
• It adds some)&at automatic memor management on to$ o"!99 t&roug& di""erent means%
• T&ere's $lent o" com$onents%• Mecause Noia is using it
• obs-
8/20/2019 Qt Basics GKO 2010
14/66
1. © 2010 Digia Plc
&at do I need to no) to use it-
• As mentioned be"ore Qt &as bindings "or di""erentlanguages, but best su$$ort is "or !99%
• I t&in t&at le#el "or learning Qt is 4ust basics o"$rogramming and !99%
•
I &ad onl done some !99 be"ore started, but $lento" $rogramming @mostl )it& a#aB%
• Kno)ing about !99 &el$s%• Pointers• Fe"erences•
3acros• Tem$lates• All t&at )eird stu""
8/20/2019 Qt Basics GKO 2010
15/66
17 © 2010 Digia Plc
&at are t&e "undamentals o" Qt-
• =ource: &tt$:665t%noia%com6doc6ob4ect%&tml
• 3ostl automatic memor management t&roug&di""erent means
• &ierarc&ical and 5uerable ob4ect trees t&at organiOe
ob4ect o)ners&i$• &tt$:665t%noia%com6doc6ob4ecttrees%&tml
• Im$lemented )it& Q+b4ects
• im$licitl s&ared classes• &tt$:66doc%trolltec&%com6s&ared%&tml
• #ariet o" di""erent smart $ointers
8/20/2019 Qt Basics GKO 2010
16/66
1 © 2010 Digia Plc
&at are t&e "undamentals o" Qt
• ob4ect communication met&od called signals and slots• &tt$:665t%noia%com6doc6signalsandslots%&tml
• Im$lemented t&roug& 3+!&tt$:665t%noia%com6doc6moc%&tmlEmoc
• e#ents and e#ent "ilters• &tt$:665t%noia%com6doc6e#entsand"ilters%&tml
• 5uerable and designable ob4ect $ro$erties• &tt$:665t%noia%com6doc6$ro$erties%&tml
• Im$lemented t&roug& 3+!
&tt$:665t%noia%com6doc6moc%&tmlEmoc
8/20/2019 Qt Basics GKO 2010
17/66
1? © 2010 Digia Plc
&at are t&e "undamentals o" Qt
• conte(tual string translation "or internationaliOation• &tt$:665t%noia%com6doc6i1Hn%&tml
• =im$l use Q+b4ect::tr@Te(tB
• inter#al dri#en timers
• &tt$:665t%noia%com6doc6timers%&tml• ell lea#e t&ese out, but its good to mention t&em%
• Q+b4ects accom$anied )it& moc are mostl t&esource o" magic in Qt
• T&e enable some o" t&e cool "unctionalit based on
in&eritance "rom Q+b4ect and code generation%
8/20/2019 Qt Basics GKO 2010
18/66
1H © 2010 Digia Plc
&at are "undamentals o" Qt-
• T&e 3eta8+b4ect !om$iler, moc, is t&e $rogram t&at&andles Qt's !99 e(tensions%
• &tt$:665t%noia%com6doc6moc%&tmlEmoc
• Pro#ides us t&e Qts 3eta8+b4ect =stem• &tt$:665t%noia%com6doc6metaob4ects%&tml
http://qt.nokia.com/doc/moc.htmlhttp://qt.nokia.com/doc/moc.html
8/20/2019 Qt Basics GKO 2010
19/66
1J © 2010 Digia Plc
/ierarc&ical and 5uerable ob4ect trees
• =ource: &tt$:665t%noia%com6doc6ob4ecttrees%&tml
• Q+b4ects organiOe t&emsel#es in ob4ect trees%
• &en ou create a Q+b4ect )it& anot&er ob4ect as$arent%
• It's added to t&e $arent's c&ildren@B list%• It is deleted )&en t&e $arent is%
• A Q=&ortcut @eboard s&ortcutB is a c&ild o" t&erele#ant )indo)%
•
=o )&en t&e user closes t&at )indo), t&e s&orcut isdeleted too%
8/20/2019 Qt Basics GKO 2010
20/66
20 © 2010 Digia Plc
!onstruction6Destruction +rder o"Q+b4ects
• ou can construct a tree o" Q+b4ects in an order ou )ant%• +" course ou &a#e to create t&e Q+b4ect be"ore ou can use it
as a $arent%
• A"ter t&e ob4ect tree &as been created, it can be destroedin an order%
• &en an Q+b4ect in t&e tree is deleted• i" t&e ob4ect &as a $arent
• t&e destructor automaticall remo#es t&e ob4ect "rom its $arent
• i" t&e ob4ect &as c&ildren• t&e destructor automaticall deletes eac& c&ild
• No Q+b4ect is deleted t)ice, regardless o" t&e order o"destruction%
8/20/2019 Qt Basics GKO 2010
21/66
21 © 2010 Digia Plc
!onstruction6Destruction order o"Q+b4ects
• It loos somet&ing liet&is: $arent
c&ild c&ild c&ild
c&ild
8/20/2019 Qt Basics GKO 2010
22/66
22 © 2010 Digia Plc
/ierarc&ical and 5uerable ob4ecttrees
• e do a delete on onec&ild: $arent
c&ild c&ild c&ild
c&ild
8/20/2019 Qt Basics GKO 2010
23/66
2* © 2010 Digia Plc
/ierarc&ical and 5uerable ob4ecttrees
• e get:
$arent
c&ild c&ild
8/20/2019 Qt Basics GKO 2010
24/66
2. © 2010 Digia Plc
&at is t&e stac-
• =tac is somet&ing lie:
• Image source:&tt$:66)))%a$artmentt&era$%com6uimages6n6.81?8stac8dra)ers81%4$g
8/20/2019 Qt Basics GKO 2010
25/66
27 © 2010 Digia Plc
&at is t&e stac-
• =ource: &tt$:66en%)ii$edia%org6)ii6!allstac
• A call stac is a stac data structure• stores in"ormation about t&e acti#e subroutines
• T&is ind o" stac is also no)n as
• an e(ecution stac• control stac• "unction stac• run8time stac• t&e stac
• &en memor allocation &a$$ens to t&e stac• It )ill be automaticall released a"ter it goes out o"
sco$e%
8/20/2019 Qt Basics GKO 2010
26/66
2 © 2010 Digia Plc
&at is t&e &ea$-
• =ource:&tt$:66en%)ii$edia%org6)ii6Dnamicmemorallocation
• dnamic memor allocation• also no)n as &ea$8based memor allocation
• is t&e allocation o" memor storage "or use during t&e runtime
• Dnamicall allocated memor e(ists until it is released• e($licitl b t&e $rogrammer
• lie in !99
• b t&e garbage collector• lie in a#a and !E
• T&is is in contrast to static memor allocation, )&ic& &as a "i(edduration% It is said t&at an ob4ect so allocated &as a dnamicli"etime @as in stacB%
8/20/2019 Qt Basics GKO 2010
27/66
2? © 2010 Digia Plc
Im$licitl s&ared classes
• =ource: &tt$:66doc%trolltec&%com6s&ared%&tml
• &en ou see stac allocated ob4ect• t&e mig&t not al)as be storing all t&e data in t&e stac
• Mut data mig&t be in t&e &ea$• t&e stac is onl used "or automatic dere"erencing
• =tac ob4ects $oint to a &ea$ allocated s&ared data%
• A s&ared class consists o":• a $ointer to a s&ared data bloc t&at contains:
• a re"erence count• t&e data%
8/20/2019 Qt Basics GKO 2010
28/66
2H © 2010 Digia Plc
Im$licitl s&ared classes
Im$licitl s&aredclass
re"erence count data
stac
&ea$
8/20/2019 Qt Basics GKO 2010
29/66
2J © 2010 Digia Plc
Im$licitl s&ared classes
• &en a s&ared ob4ect is created• it sets t&e re"erence count to 1
• t&e re"erence count is incremented )&ene#er a ne)ob4ect re"erences t&e s&ared data
• and decremented )&en t&e ob4ect dere"erences t&es&ared data
• T&e s&ared data is deleted )&en t&e re"erence countbecomes Oero
8/20/2019 Qt Basics GKO 2010
30/66
*0 © 2010 Digia Plc
Im$licitl s&ared classes
• =o )&en ou see somet&ing lie:• Q=tring "oo R S"ooS
• Q=tring "oo is in t&e stac• MT it &as a re"erence to a data bloc )&ic& &as
• a re"erence count• 1
• and t&e data• S"oo
8/20/2019 Qt Basics GKO 2010
31/66
*1 © 2010 Digia Plc
Im$licitl s&ared classes
• =o )&en ou do Q=tring bar R "oo• Q=tring class no) does a s&allo) co$ @to t&e stacB
• t&e "oo and bar no) actuall $oint to t&e =A3; data bloc
• onl t&e re"erence count )as increased• 2
• I" ou no) do bar%a$$end@SbarSB• No) t&e Q=tring class does a dee$ co$ "or bar%
• T&e data "rom "oo )as co$ied%• SbarS )as a$$ended to it%
• re"erence count is no) 1
• "oos re"erence count is no) 1%
• =im$le, isnt it
8/20/2019 Qt Basics GKO 2010
32/66
*2 © 2010 Digia Plc
Di""erent smart $ointers
• =ource: &tt$:66labs%trolltec&%com6blogs6200J60H6276count8)it&8me8&o)8man8smart8$ointer8classes8
does85t8&a#e6
Q=&aredDataPointer 6
Q;($licitl=&aredDataPointer
Im$lements så o" data@not o" $ointersB, im$licitl ande($licitl, res$ecti#el% T&eQ=&aredDataPointer classre$resents a $ointer to anim$licitl s&ared ob4ect%
Q=&aredPointer Im$lements re"erence8countedstrong så o" $ointers%Q=&aredPointer )ill delete t&e
$ointer it is &olding )&en itgoes out o" sco$e, $ro#ided noot&er Q=&aredPointer ob4ectsare re"erencing it%
8/20/2019 Qt Basics GKO 2010
33/66
** © 2010 Digia Plc
Di""erent smart $ointers
QeaPointer Im$lements re"erence8counted )ea
så o" $ointers% T&e QeaPointer isan automatic )ea re"erence to a$ointer in !99% It cannot be used todere"erence t&e $ointer directl, but itcan be used to #eri" i" t&e $ointer &asbeen deleted or not in anot&er conte(t%
QeaPointer ob4ects can onl becreated b assignment "rom aQ=&aredPointer%
Q=co$edPointer 6Q=co$edArraPointer
Im$lements non8re"erence8countedstrong $ointer )ra$$er
@Q=&aredPointers little brot&erB% T&eQ=co$edPointer class stores a $ointer toa dnamicall allocated ob4ect, anddeletes it u$on destruction%
8/20/2019 Qt Basics GKO 2010
34/66
*. © 2010 Digia Plc
Qt ob4ect model: =ignals and slots
• =ource: &tt$:665t%noia%com6doc6signalsandslots%&tml
• It's a )a "or Q+b4ects to communicate )it&outno)ing eac& ot&er%
8/20/2019 Qt Basics GKO 2010
35/66
*7 © 2010 Digia Plc
=ignals and slots
• =ignals are emited%• =lots recei#e signals%
• =ignals and slots are connected t&roug&Q+b4ect::connect
• 3an slots can be connected to a signal%• =ignals can be connected to signals%
8/20/2019 Qt Basics GKO 2010
36/66
* © 2010 Digia Plc
=ignals and slots
QObject* sender = new QObject;
QObject* receiver = new QObject;
/* This will connect the signal for senders destruction
* to receivers deleteLater. It will result to a situation
* where if sender is deleted, the signal destroyed()
* will be sent ust before destruction and it will trigger* the receivers deleteLater which will result the receiver
* being deleted as well. */
QObject!!connect(sender, SIGNAL(destroyed()),
receiver, SLOT(deleteLater()));
sender"#deleteLater();
8/20/2019 Qt Basics GKO 2010
37/66
*? © 2010 Digia Plc
;#ents and e#ent "ilters
• =ource: &tt$:66doc%trolltec&%com6e#entsand"ilters%&tml
• In Qt, e#ents are ob4ects, deri#ed "rom t&e abstractQ;#ent class%
8/20/2019 Qt Basics GKO 2010
38/66
*H © 2010 Digia Plc
/o) e#ents are deli#ered-
• =ource:&tt$:665t%noia%com6doc6e#entsand"ilters%&tmlE&o)8e#ents8are8deli#ered
• As e#ent occurs•
Qt creates an e#ent ob4ect to re$resent it• b constructing an instance o" t&e a$$ro$riate Q;#ent
subclass• &tt$:66doc%trolltec&%com65e#ent%&tml
• ie% Q3ouse;#ent, QKe;#ent, QPaint;#ent
• deli#ers it to a $articular instance o" Q+b4ect @or one o"
its subclassesB b calling its e#ent@B "unction
http://doc.trolltech.com/qevent.htmlhttp://doc.trolltech.com/qevent.html
8/20/2019 Qt Basics GKO 2010
39/66
*J © 2010 Digia Plc
/o) e#ents are deli#ered-
• e#ent@B "unction does not &andle t&e e#ent itsel" • but based on t&e t$e o" e#ent deli#ered
• it calls an e#ent &andler "or t&at s$eci"ic t$e o" e#ent
• sends a res$onse based on )&et&er t&e e#ent )as acce$tedor ignored
8/20/2019 Qt Basics GKO 2010
40/66
.0 © 2010 Digia Plc
;#ent t$es
• =ource:&tt$:665t%noia%com6doc6e#entsand"ilters%&tmlEe#ent8t$es
• 3ost e#ent t$es &a#e s$ecial classes
• As said earlier, t&e are descents o" Q;#ent• &tt$:665t%noia%com6doc65e#ent%&tml
8/20/2019 Qt Basics GKO 2010
41/66
.1 © 2010 Digia Plc
;#ent t$es
• common ones are:• QFesiOe;#ent &tt$:665t%noia%com6doc65resiOee#ent%&tml
• FesiOe e#ents
• QPaint;#ent &tt$:665t%noia%com6doc65$ainte#ent%&tml• Paint e#ents
• Q3ouse;#ent&tt$:665t%noia%com6doc65mousee#ent%&tml
• 3ouse e#ents
• QKe;#ent &tt$:665t%noia%com6doc65ee#ent%&tml• Ke e#ents
• Q!lose;#ent &tt$:665t%noia%com6doc65closee#ent%&tml• !lose e#ents @lie )indo), dialog, a$$licationB
8/20/2019 Qt Basics GKO 2010
42/66
.2 © 2010 Digia Plc
;#ent &andlers
• =ource:&tt$:665t%noia%com6doc6e#entsand"ilters%&tmlEe#ent8&andlers
• suall t&ere's a #irtual "unction in a base class%•
lie Qidget• /andling an e#ent &a$$ens so t&at:
• ou in&erit t&e class and im$lement t&e #irtual "unction%
8/20/2019 Qt Basics GKO 2010
43/66
.* © 2010 Digia Plc
;#ent "ilters
• =ource:&tt$:665t%noia%com6doc6e#entsand"ilters%&tmlEe#ent8"ilters
• It is $ossible to )rite e#ent "ilters•
;#ent "ilters can loo or e#en interce$t t&e e#ents• In&erit Q+b4ect
• Im$lement bool Q+b4ect::e#entGilter@Q+b4ect Uob4ect,Q;#ent Ue#entB
• T&e )or $er Q+b4ect basis• ou set an e#ent "ilter to a Q+b4ect )it&
• Q+b4ect::install;#entGilter@B&tt$:665t%noia%com6doc65ob4ect%&tmlEinstall;#entGilter
8/20/2019 Qt Basics GKO 2010
44/66
.. © 2010 Digia Plc
Querable and designable ob4ect$ro$erties
• =ource: &tt$:665t%noia%com6doc6$ro$erties%&tml
• A $ro$ert be&a#es lie a class data member%
• It &as additional "eatures accessible t&roug& t&e 3eta8+b4ect =stem%
• It is im$lemented t&roug& moc %• Needs Q+M;!T in t&e class &eader declaration%
8/20/2019 Qt Basics GKO 2010
45/66
.7 © 2010 Digia Plc
Querable and designable ob4ect$ro$erties
• ou can do somet&ing lie:$ %&''T+(bool enabled - isnabled IT setnabled)
• bool re"ers to t&e t$e o" t&e $ro$ert
• enabled is t&e $ro$ert name
• F;AD ob#iousl re"ers to t&e reading
• is;nabled is t&e "unction called "or reading• it &as to &a#e a $ublic im$lementation
• FIT;, again ob#iousl, re"ers to )riting
• set;nabled is t&e "unction to be called )&en )riting• it &as to &a#e a $ublic im$lementation
8/20/2019 Qt Basics GKO 2010
46/66
. © 2010 Digia Plc
3oc and meta8ob4ect model
• =ource: &tt$:665t%noia%com6doc6moc%&tmlEmoc
• T&e 3eta8+b4ect !om$iler, moc, is t&e $rogram t&at&andles Qt's !99 e(tensions%
• Pro#ides us t&e Qts 3eta8+b4ect =stem
• 3agic &a$$ens t&roug& macros lie:• Q+M;!T
• QPF+P;FT
• Q;N3=
• signals:
• $ublic slots:
• $ri#ate slots:
8/20/2019 Qt Basics GKO 2010
47/66
.? © 2010 Digia Plc
3oc and meta8ob4ect model
• T&is moc tool reads our &eader "ile
• Tries to "ind t&e Q+M;!T macro
• enerates meta8ob4ect code "or t&ose classes• code "or signals and slots
• )&ere signals, $ublic slots or $ri#ate slots are used• code "or $ro$erties
• )&ere QPF+P;FT is used
• code "or enums• )&ere Q;N3= is used
• Fegistering an enumeration t$e maes t&e enumeratornames a#ailable "or use in calls to Q+b4ect::setPro$ert@B%
8/20/2019 Qt Basics GKO 2010
48/66
.H © 2010 Digia Plc
/o) do I do I a$$lications )it& it-
• ou can do )it& a designer lie in Qt !reator
• +r lie real N;FD=, b &and%• ea&, 4ust idding%%%
• T&e Qt !reator is mostl in t&e )a o" ou )ant to do
ant&ing more com$licated%• Its also "airl cumbersome to add our o)n
com$onents to t&e designers com$onent librar%
8/20/2019 Qt Basics GKO 2010
49/66
.J © 2010 Digia Plc
/o) do I do I a$$lications )it& it-
• T&eres @at t&e momentB t)o )as o" doing I%• Qidget based a$$roac&
• ou do in&erit Qts com$onents and add "unctionalit• In&erit 4ust Qidget
• Im$lement Qidget::$aint;#ent@QPaint;#entUB• do custom $ainting )it& QPainter
•
&tt$:66doc%trolltec&%com65$ainter%&tml• se Qts stle s&eets to stle t&e )idgets
• &tt$:66doc%trolltec&%com6stles&eet%&tml
• ra$&ics Lie) "rame)or• Totall custom dra)ing%• !an use Qidgets in ra$&ics Lie) t&roug& $ro(s%• &tt$:66doc%trolltec&%com6gra$&ics#ie)%&tml
• Qt Quic• !ustom I
• Declarati#e descri$tion o" t&e I )it& ;cma=cri$t
8/20/2019 Qt Basics GKO 2010
50/66
70 © 2010 Digia Plc
/o) do I do /ello orld-
include 0QtGui/QApplication#
include 0QtGui/QLabel#
int 1ain(int argc, char **argv)
2
QApplication a(argc, argv);
/** 3reate %Label to stac4* so we don5t have to delete it. */
QLabel label(67ello orld86);
/** 9how it8 */
label.show();
/** :ic4 off the event loo. */ return a.e
8/20/2019 Qt Basics GKO 2010
51/66
71 © 2010 Digia Plc
/o) do I do /ello orld-
• A bit more com$licated /ello orld )it&Q3ainindo), QGrame, QLMo(
8/20/2019 Qt Basics GKO 2010
52/66
72 © 2010 Digia Plc
/o) do I do e#ents-
• =ending e#ents$ bool %3orelication!!sendvent(%bect*
receiver, %vent* event)
• Fecei#ing e#ents•
se t&e s$ecialiOed e#ent &andlers• $aint;#ent• resiOe;#ent
• etcV
8/20/2019 Qt Basics GKO 2010
53/66
7* © 2010 Digia Plc
/o) do I do signals and slots-
• Ill s&o) t&e e(am$le code%%%
8/20/2019 Qt Basics GKO 2010
54/66
7. © 2010 Digia Plc
/o) do I do com$onents-
• T&e basic idea is to &a#e #er atomic use cases%
• Tr to ee$ t&e de$endencies as lo) as $ossible%
• se signals and slots "or communication%
• Tr to use basic t$es as $arameters "or t&e signals
and slots
8/20/2019 Qt Basics GKO 2010
55/66
77 © 2010 Digia Plc
/o) do I do com$onents-
• A sim$le com$onent )it&out gra$&ical inter"ace%• Q!ounter : $ublic Q+b4ect
• $ublic• int #alue@B
• $ublic slots• increment@B• increment@int amountB• decrement@B• setLalue@int ne)LalueB
• signals• #alue!&anged@int ne)LalueB• #alue!&anged@const Q=tringC #alueB• #alue!&angedDelta@int deltaB
• $ri#ate• int m#alue
8/20/2019 Qt Basics GKO 2010
56/66
7 © 2010 Digia Plc
/o) do I do com$onents
• e )ra$ t&at Q!ounter to a gra$&ical re$resentation• Qra$&ical!ounter : $ublic Q
8/20/2019 Qt Basics GKO 2010
57/66
7? © 2010 Digia Plc
/o) do I do com$onents-
•
8/20/2019 Qt Basics GKO 2010
58/66
7H © 2010 Digia Plc
/o) do I do com$onents-
• T&en )e need a reset button%• Gor t&at )e'll create a iterator )&ic& iterates o#er
Qra$&ical!ounters%
• T&e iterator )ill send a re"erence to a "oundQra$&ical!ounter e#er time it "inds one%
• e'll use t&e Q+b4ects ob4ect tree "eature to im$lement t&is"eature
• Q+b4ects are usuall created b assigning a $arent%
• T&at created ob4ect )ill be t&e c&ild o" t&e $arent ob4ect
• T&e tree can be easil iterated%
8/20/2019 Qt Basics GKO 2010
59/66
7J © 2010 Digia Plc
/o) do I do com$onents-
• Vreset button continues:• e'll )ire 4ust an ordinar QPus&Mutton to a slot )&ic&
)ill gi#e t&e Q!ounterIterator a starting $oint "oriteration
• e'll )ire t&e "ound signal to one o" t&e slots )&ic& )ill
reset t&e counter%
8/20/2019 Qt Basics GKO 2010
60/66
0 © 2010 Digia Plc
/o) do I do com$onents-
• + so )e'#e glued all t&is toget&er )it& code%%%
8/20/2019 Qt Basics GKO 2010
61/66
1 © 2010 Digia Plc
Qt Quic
• &tt$:66doc%5t%noia%com65t5uic%&tml
• Qt ser Inter"ace !onstruction Kit
• Girst bundle release o" Qt Quic on .%?
• Tec&nolog to build intuiti#e modern8looing "luid user inter"aces
•
Qt Quic is conce$t o" • Tools:
• Qt!reator
• Q3< Designer
• Q3
8/20/2019 Qt Basics GKO 2010
62/66
2 © 2010 Digia Plc
Q3<
• =cri$t language
• ses a#a=cri$t as glue code "or controlling t&e be&a#iour o"t&e user inter"ace
• Declarati#e )a to de"ine I be&a#iour
• !ontains set o" #er basic user inter"ace controls called as Q3<elements "or e(am$le
• &tt$:66doc%5t%noia%com65declarati#eelements%&tml
• Fectangle
• Te(t
• Image
• Glicable• ;lements &a#e $ro$erties )&ic& can &a#e bindings to ot&er
$ro$erties
8/20/2019 Qt Basics GKO 2010
63/66
* © 2010 Digia Plc
Q3<
• !om$lete a$$lications can be made )it& Q3< 9 a#a=cri$t ande(ecuted b Q3
8/20/2019 Qt Basics GKO 2010
64/66
. © 2010 Digia Plc
Qt Quic lins
• Qt .%? and Qt !reator• &tt$:665t%noia%com6do)nloads6
• Qt Quic documentation• &tt$:66doc%5t%noia%com65t5uic%&tml
• Qt Quic Plaground• &tt$s:66$ro4ects%"orum%noia%com65t5uic$laground
• Qt Mubble
8/20/2019 Qt Basics GKO 2010
65/66
7 © 2010 Digia Plc
Questions-
• I" )e &a#e time "or anV
8/20/2019 Qt Basics GKO 2010
66/66
T&an ou
tarmo%aidantaustaWdigia%com
mailto:[email protected]:[email protected]Top Related