Anda di halaman 1dari 27

Q t Q uic k

For C ++ D evelopers

#ho $m I%
I am R oberto R aggi P rincipal E ngineer at Nokia, QtD F P art of the Qt C reator team In addition, I contrib ted to the design and the implementation of the Q! " lang age

Q t Q ick
Qt Q ick is a set of technologies designed to help developers create modern&looking interfaces
lang age for describing 'Is (Q! ") set of ser interface elements (Item, R ectangle, "ist*ie+, Flickable, , ) Q t C reator -ools For Q! "

-he Q ! " "ang age


Q! " is a simple .et po+erf l programming lang age $ declarative lang age
-he changes in the 'I are e/pressed as sets of propert. e/pressions (e0g0 this width is always half of that width)

E as. to learn
12 3 N&like s.nta/ for the ob4ect declarations 1ava2 cript to define propert. bindings

-he Q ! " "ang age


5 ilds on the Qt ! eta 3 b4ect
P roperties, signals, and invokable methods

*ersioned mod le s.stem 5 ilt&in s pport for animations


2 tates and transitions 5 ehaviors for properties

Integrates +ith e/isting technologies


Q t6 C ++, Q t6 7D , Q t ! obilit., Q t#eb8it, 000

-he Q ! " "ang age


$lso, Q ! " is designed to be
embedded into e/isting applications e/tended +ith C ++

Q t D eclarative ! od le

-he Q t D eclarative C ++ $P Is
QD eclarativeE ngine
core of the Q! " r ntime provides an environment for Q! " components

-he Q t D eclarative C ++ $P Is
QD eclarativeE ngine
core of the Q! " r ntime provides an environment for Q! " components

QD eclarativeC onte/t
provides a set of properties that can be accessed b. name from Q ! "

-he Q t D eclarative C ++ $P Is
QD eclarativeE ngine
core of the Q! " r ntime provides an environment for Q! " components

QD eclarativeC onte/t
provides a set of properties that can be accessed b. name from Q ! "

QD eclarative*ie+
Q 9raphics*ie+&based +idget that can be sed to displa. Q! " interfaces

-he Q t D eclarative C ++ $P Is
#ell, those classes are connected
Q D eclarative*ie+ holds a Q D eclarativeE ngine Q D eclarativeE ngine keeps a reference to the root Q D eclarativeC onte/t

"et:s do it;
"et:s tr. to se those classes in Q t C reator0

E /posing D ata
QD eclarativeC onte/t allo+s the application to e/pose data
setC onte/tP ropert.(name, val e) setC onte/t3 b4ect(ob4ect)

-he conte/ts form a hierarch.


E ach conte/t has a parent conte/t -he root of this hierarch. is the Q D eclarativeE ngine:s root conte/t

C stom C ++ -.pes
C stom -.pes are registered sing
<mlR egister-.pe=C pp-.>(mod,ver,<mlName)
#here C ppTy is a C++ t.pe, mod is the mod le name, ver is the initial version n mber and qmlName is the name of the component0

For e/ample,
<mlR egister-.pe=C ontact>(?m.@, A,B, ?C ontact@)

C stom C ++ -.pes
Ne+ t.pes m st
Inherit from a Q3 b4ect based class (e0g0 Q D eclarativeItem, Q $bstractItem! odel) $dd properties sing the QCP R 3 P E R -D macro and the N3 -IFD attrib te
Q CP R 3 P E R -D(int p R E $D p #R I-E setP N3 -IFD pC hanged)

Q ! " P ropert. 5 indings


P ropert. bindings are observed b. the Q! " engine
R ectangle E +idthF parent0+idthG , on#idthC hangedF E / / generated slot console0log(?+idth changed@, +idth) H H

C stom C ++ -.pes
int p() const E ret rn CpG H void setP (int p) E if (Cp II p) ret rnG Cp I pG / /emitted whenever the value changes emit pC hanged()G H

C stom C ++ -.pes
! ethods marked as Q CIN*3 8$5 "E can be sed as normal 12 f nctions
Q CIN*3 8$5 "E void initialiJe()G 6 6 C ++ C omponent0onC ompletedF E initialiJe()G H6 6 Q!"

$ll Q t signals are available in Q ! "


Q C2 I9N$"2 F void triggered()G 6 6 C ++ on-riggeredF E console0log(?triggered@)G H6 6 Q!"

"et:s do it in Q t C reator

C stom C ++ -.pes
QD eclarativeItem
E /tends Q 9raphics 3 b4ect D efines properties that are common to all vis al items (e0g0 anchors, /, ., +idth, height)

Do can s bclass QD eclarativeItem to provide .o r o+n c stom vis al item


C lear the ItemHasNoC ontents flag 3 verride the method paint()

C stom C ++ -.pes
Items s ch as "ist*ie+ and R epeater re< ire data models to displa. data Do can s bclass Q$bstractItem! odel to provide data for those items
remember to set the ser role names sing Q $bstractItem! odelFFsetR oleNames(names)

"et:s tr. it;

E /tension P l gins
Ne+ c stom Q ! " E /tensions m st
Inherit from Q D eclarativeE /tensionP l gin
3 verride the method register-.pes(mod le) P erform c stom initialiJation in initialiJeE ngine()

P rovide a <mldir file that tells the Q! " engine to load the pl gin
<mldir files are eas. to +rite

Do need to b ndle the code in a librar. and e/port the pl gin sing the QCE K P 3 R -CP "'9INL macro

Deah, It:s Q t C reator time;

$dvanced -opics
QD eclarativeE ngine +itho t a QD eclarative*ie+ $dvanced image loading +ith QD eclarativeImageP rovider $ttached properties
$nnotate t.pes +ith additional properties

C omm nit.
httpF6 6 <t0nokia0com6 httpF6 6 labs0<t0nokia0com6 <t&<ml mailing list
httpF6 6 lists0trolltech0com6 mailman6 listinfo6 <t&<ml

M<t&<ml on irc0freenode0org httpF6 6 <t0gitorio s0org6 <t httpF6 6 <t0gitorio s0org6 <t&components

-hank .o ;

Anda mungkin juga menyukai