Tải bản đầy đủ - 0 (trang)
Appendix A. Obtaining and Installing Qt

Appendix A. Obtaining and Installing Qt

Tải bản đầy đủ - 0trang

A.ObtainingandInstallingQt

ANoteonLicensing

InstallingQt/Windows

InstallingQt/Mac

InstallingQt/X11

ThisappendixexplainshowtoobtainandinstallaGPLeditionof

Qtontoyoursystem.EditionsareavailableforWindows,Mac

OSX,andX11(forLinuxandmostversionsofUnix).TheprebuiltbinariesforWindowsandMacOSXincludeSQLite,a

publicdomainin-processdatabase,togetherwithaSQLite

driver.TheversionsbuiltfromsourcecanincludeSQLiteatyour

option.Tobegin,downloadthelatestversionofQtfrom

http://www.trolltech.com/download/.Ifyouplantodevelop

commercialsoftware,youwillneedtobuyacommercialedition,

andwhenyougetityoushouldfollowtheinstallation

instructionsthatareprovided.

TrolltechalsoprovidesQt/EmbeddedLinuxforbuilding

applicationsforLinux-basedembeddeddevicessuchasPDAs

andmobilephones.Ifyouareinterestedincreatingembedded

applications,youcanobtainQt/EmbeddedLinuxfromTrolltech's

downloadwebpage.

Theexampleapplicationsusedinthisbookareavailablefrom

thebook'swebsite,

http://www.informit.com/title/0132354160.Inaddition,Qt

providesmanysmallexampleapplicationslocatedinthe

examplessubdirectory.



ANoteonLicensing

Qtisavailableintwoforms:opensourceandcommercial.The

opensourceeditionsareavailablefreeofcharge;the

commercialeditionscanbepurchasedforafee.



Ifyouwanttodistributetheapplicationsthatyoucreatewith

anopensourceeditionofQt,youmustcomplywiththespecific

termsandconditionslaiddowninthelicensesforthesoftware

youusetocreatetheapplications.Foropensourceeditions,the

termsandconditionsincludetherequirementtousetheGNU

GeneralPublicLicense(GPL).OpenlicensessuchastheGPL

givetheapplications'userscertainrights,includingtherightto

viewandmodifythesourceandtodistributetheapplications

(onthesameterms).Ifyouwanttodistributeyourapplications

withoutsourcecode(tokeepyourcodeprivate)orifyouwant

toapplyyourowncommerciallicenseconditionstoyour

applications,youmustbuycommercialeditionsofthesoftware

youusetocreatetheapplications.Thecommercialeditionsof

thesoftwareallowyoutosellanddistributeyourapplications

onyourownterms.

ThefulllegaltextsofthelicensesareincludedwiththeGPL

versionsofQtforWindows,MacOSX,andX11,alongwith

informationonhowtoobtaincommercialversions.



IV:Appendixes





A.ObtainingandInstallingQt

ANoteonLicensing

InstallingQt/Windows

InstallingQt/Mac

InstallingQt/X11

ThisappendixexplainshowtoobtainandinstallaGPLeditionof

Qtontoyoursystem.EditionsareavailableforWindows,Mac

OSX,andX11(forLinuxandmostversionsofUnix).TheprebuiltbinariesforWindowsandMacOSXincludeSQLite,a

publicdomainin-processdatabase,togetherwithaSQLite

driver.TheversionsbuiltfromsourcecanincludeSQLiteatyour

option.Tobegin,downloadthelatestversionofQtfrom

http://www.trolltech.com/download/.Ifyouplantodevelop

commercialsoftware,youwillneedtobuyacommercialedition,

andwhenyougetityoushouldfollowtheinstallation

instructionsthatareprovided.

TrolltechalsoprovidesQt/EmbeddedLinuxforbuilding

applicationsforLinux-basedembeddeddevicessuchasPDAs

andmobilephones.Ifyouareinterestedincreatingembedded

applications,youcanobtainQt/EmbeddedLinuxfromTrolltech's

downloadwebpage.

Theexampleapplicationsusedinthisbookareavailablefrom

thebook'swebsite,

http://www.informit.com/title/0132354160.Inaddition,Qt

providesmanysmallexampleapplicationslocatedinthe

examplessubdirectory.



ANoteonLicensing

Qtisavailableintwoforms:opensourceandcommercial.The

opensourceeditionsareavailablefreeofcharge;the

commercialeditionscanbepurchasedforafee.



Ifyouwanttodistributetheapplicationsthatyoucreatewith

anopensourceeditionofQt,youmustcomplywiththespecific

termsandconditionslaiddowninthelicensesforthesoftware

youusetocreatetheapplications.Foropensourceeditions,the

termsandconditionsincludetherequirementtousetheGNU

GeneralPublicLicense(GPL).OpenlicensessuchastheGPL

givetheapplications'userscertainrights,includingtherightto

viewandmodifythesourceandtodistributetheapplications

(onthesameterms).Ifyouwanttodistributeyourapplications

withoutsourcecode(tokeepyourcodeprivate)orifyouwant

toapplyyourowncommerciallicenseconditionstoyour

applications,youmustbuycommercialeditionsofthesoftware

youusetocreatetheapplications.Thecommercialeditionsof

thesoftwareallowyoutosellanddistributeyourapplications

onyourownterms.

ThefulllegaltextsofthelicensesareincludedwiththeGPL

versionsofQtforWindows,MacOSX,andX11,alongwith

informationonhowtoobtaincommercialversions.



InstallingQt/Windows

Atthetimeofthiswriting,theWindowsinstallerwascalledqtwin-opensource-4.3.2-mingw.exe.Theversionnumberwill

probablybedifferentbythetimeyoureadthis,buttheprocess

shouldbethesame.Downloadthefileandrunittobeginthe

installationprocess.

WhentheinstallerreachestheMinGWpage,ifyoualreadyhave

theMinGWC++compiler,youmustspecifythedirectorywhere

itislocated;otherwise,checkthecheckboxandhavethe

installerinstallMinGWforyou.TheGPLversionofQtwillnot

workwithVisualC++,soifyoudonothaveMinGWalready

installed,youwillneedtoinstallit.Qt'sstandardexamplesare

automaticallyinstalled,alongwiththedocumentation.

IfyouchoosetoinstalltheMinGWcompiler,theremaybea

smalldelaybetweenthecompletionoftheMinGWinstallation

andthestartoftheQtinstallation.

Afterinstallation,youwillhaveanewfolderintheStartmenu

calledQtbyTrolltechv4.3.2(OpenSource).Thisfolderhasshortcutsto

QtAssistantandQtDesigner,andalsoonecalledQt4.3.2

CommandPromptthatstartsaconsolewindow.Whenyoustart

thiswindowitwillsettheenvironmentvariablesforcompiling

QtprogramswithMinGW.Inthiswindow,youcanrunqmake

andmaketobuildQtapplications.



InstallingQt/Mac

BeforeQtcanbeinstalledonMacOSX,Apple'sXcodeTools

mustalreadybeinstalled.TheCD(orDVD)containingthese

toolsisusuallysuppliedwithMacOSX;theycanalsobe

downloadedfromtheAppleDeveloperConnection,

http://developer.apple.com/.

IfyouhaveMacOSX10.4andXcodeTools2.x(withGCC

4.0.x)orlater,youcanusetheinstallerdescribedshortly.Ifyou

haveanearlierversionofMacOSX,oranolderversionofGCC,

youwillneedtoinstallthesourcepackagemanually.This

packageiscalledqt-mac-opensource-4.3.2.tar.gzandis

availablefromTrolltech'swebsite.Ifyouinstallthispackage,

followtheinstructionsinthenextsectionforinstallingQton

X11.

Tousetheinstaller,downloadqt-mac-opensource-4.3.2.dmg.

(Thisversionwascorrectatthetimeofthiswriting,butitwill

probablybedifferentbythetimeyoureadthis.)Double-click

the.dmgfile,andthendouble-clickthepackagecalledQt.mpkg.

Thiswilllaunchtheinstaller,whichwillinstallQtin/Developer,

alongwithitsdocumentationandthestandardexamples.

Toruncommandssuchasqmakeandmake,youwillneedtouse

aterminalwindow,forexample,Terminal.appin

/Applications/Utilities.Itisalsopossibletogenerate

Xcodeprojectsusingqmake.Forexample,togenerateanXcode

projectforthehelloexample,startaconsolesuchas

Terminal.app,changetoyourexamples/chap01/hello

directory,andenterthefollowingcommand:

qmake-specmacx-xcodehello.pro



InstallingQt/X11

Downloadthefileqt-x11-opensource-src-4.3.2.tar.gzfrom

Trolltech'swebsite.(Thisversionwascorrectatthetimeofthis

writing,butitwillprobablybedifferentbythetimeyouread

this.)ToinstallQtinitsdefaultlocationonX11,youwillneedto

beroot.Ifyoudonothaverootaccess,useconfigure'sprefixoptiontospecifyadirectorytowhichyouhave

permissiontowrite.

1. Changedirectorytothedirectorywhereyoudownloaded

thearchivefile.Forexample:

cd/tmp

2. Unpackthearchivefile:

gunzipqt-x11-opensource-src-4.3.2.tar.gz

tarxvfqt-x11-opensource-src-4.3.2.tar

Thiswillcreatethedirectory/tmp/qt-x11-opensourcesrc-4.3.2.QtrequiresGNUtar;onsomesystemsitis

calledgtar.

3. Executetheconfiguretoolwithyourpreferredoptionsto

buildtheQtlibraryandthetoolssuppliedwithit:

cd/tmp/qt-x11-opensource-src-4.3.2

./configure

Youcanrun./configure-helptogetalistof

configurationoptions.

4. TobuildQt,type

make

Thiswillcreatethelibraryandcompileallthedemos,



examples,andtools.Onsomesystems,makeiscalled

gmake.

5. ToinstallQt,type

su-c"makeinstall"

andentertherootpassword.(Onsomesystems,the

commandissudomakeinstall.)ThiswillinstallQtinto

/usr/local/Trolltech/Qt-4.3.2.Youcanchangethe

destinationbyusingthe-prefixoptionwithconfigure,

andifyouhavewriteaccesstothedestinationyoucan

simplytype:

makeinstall

6. SetupcertainenvironmentvariablesforQt.

Ifyourshellisbash,ksh,zsh,orsh,addthefollowingtwo

linestoyour.profilefile:

PATH=/usr/local/Trolltech/Qt-4.3.2/bin:$PATH

exportPATH

Ifyourshelliscshortcsh,addthefollowinglinetoyour

.loginfile:

setenvPATH/usr/local/Trolltech/Qt-4.3.2/bin:$PATH

Ifyouused-prefixwithconfigure,usethepathyou

specifiedinsteadofthedefaultpathshownhere.

Ifyouareusingacompilerthatdoesnotsupportrpath,

youmustalsoextendtheLD_LIBRARY_PATHenvironment

variabletoinclude/usr/local/Trolltech/Qt-4.3.2/lib.

ThisisnotnecessaryonLinuxwithGCC.

Qtcomeswithademoapplication,qtdemo,thatshowsoffmany



ofthelibrary'sfeatures.Itservesasanicestartingpointtosee

whatQtcando.ToseeQt'sdocumentation,eithervisit

http://doc.trolltech.com/orrunQtAssistant,Qt'shelp

application,invokedbytypingassistantinaconsolewindow.



B.BuildingQtApplications

Usingqmake

UsingThird-PartyBuildTools

BuildingQtapplicationsisgreatlysimplifiedbytheuseofa

buildtool.Threeoptionsareopentous:Wecanusetheqmake

toolsuppliedwithQt,wecanuseathird-partybuildtool,orwe

canuseanintegrateddevelopmentenvironment(IDE).

Theqmaketoolgeneratesaplatform-specificmakefilefroma

platform-neutral.profile.Thetoolhasthenecessarylogicto

invokeQt'scode-generatingtools(moc,uic,andrcc)built-in.

Wehaveusedqmakeforalltheexamplesinthebook,inmost

casesusingrelativelysimple.profiles.Infact,qmakeprovides

arichrangeoffeaturesincludingtheabilitytocreatemakefiles

thatrecursivelyinvokeothermakefilesandtoswitchcertain

featuresonoroffdependingonthetargetplatform.Inthefirst

sectionofthisappendix,wewillreviewqmakeandintroduce

someofitsmoreadvancedfeatures.

Intheory,anythird-partybuildtoolcanbeusedforQt

development,butitismucheasiertouseonethatisalready

Qt-aware.WewilllookatsomeoftheQt-awarebuildtoolsin

thesecondsection.

SomedeveloperswouldratheruseanIDEtobuildtheir

applications.TrolltechprovidessoftwaretointegratewithVisual

StudioandEclipse(showninFigureB.1),andtheopensource

IDEsKDevelopandQDevelop—bothwrittenusingQt—provide

excellentsupportforQtdevelopment.

FigureB.1.TheQtVisualStudioandEclipseintegrations

inaction

[Viewfullsizeimage]



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Appendix A. Obtaining and Installing Qt

Tải bản đầy đủ ngay(0 tr)

×