+ All Categories
Home > Documents > Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt...

Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt...

Date post: 05-Jan-2019
Category:
Upload: lequynh
View: 237 times
Download: 0 times
Share this document with a friend
34
Qt Essentials - Fundamentals of Qt Module Qt Essentials - Training Course Produced by Nokia, Qt Development Frameworks Material based on Qt 4.7, created on December 15, 2010 http://qt.nokia.com 1/28
Transcript
Page 1: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Qt Essentials - Fundamentals of Qt ModuleQt Essentials - Training Course

Produced by Nokia, Qt Development Frameworks

Material based on Qt 4.7, created on December 15, 2010

http://qt.nokia.com

1/28

Page 2: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Module: Fundamentals of QtThe Story of QtDeveloping a Hello World ApplicationHello World using Qt CreatorPractical Tips for Developers

Fundamentals of Qt 2/28

Page 3: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Module Learning Objectives

• Learn ...• ... about the history of Qt• ... about Qt’s ecosystem• ... a high-level overview of Qt• ... how to create first hello world program• ... build and run a program cross platform• ... to use Qt Creator IDE• ... some practical tips for developing with Qt

Fundamentals of Qt 3/28

Page 4: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Module: Fundamentals of Qt

The Story of QtDeveloping a Hello World ApplicationHello World using Qt CreatorPractical Tips for Developers

Fundamentals of Qt The Story of Qt 4/28

Page 5: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Meet Qt• Qt Development Frameworks founded in 1994

• Trolltech acquired by Nokia in 2008• More than 250 employees in eight locations worldwide• Trusted by over 6,500 companies worldwide

• Qt: a cross-platform application and UI framework• For desktop, mobile and embedded development• Used by more than 350,000 commercial and open source

developers• Backed by Qt consulting, support and training

See Service & Partners

Fundamentals of Qt The Story of Qt 5/28

Page 6: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Qt is used everywhere

Fundamentals of Qt The Story of Qt 6/28

Page 7: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

The Qt virtuous cycle

See Qt Business Model

Fundamentals of Qt The Story of Qt 7/28

Page 8: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Why Qt

• Write code once to target multiple platforms• Produce compact, high-performance applications• Focus on innovation, not infrastructure coding• Choose the license that fits you

• Commercial, LGPL or GPL

• Count on professional services, support and training• Take part in an active Qt ecosystem

15 years of customer success and community growth

Fundamentals of Qt The Story of Qt 8/28

Page 9: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Qt Architecture

Fundamentals of Qt The Story of Qt 9/28

Page 10: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Qt Demo

• Let’s have a look at the QtDemo Application• Demo $QTDIR/bin/qtdemo

• Comes with every Qt installation

Technology DemoPainting Demonstrations/Path StrokingWidgets Demonstrations/BooksWidgets Demonstrations/TextEditGraphics View Demonstrations/40.000 ChipsOpenGL Demonstrations/BoxesWebKit Demonstrations/Browser

Fundamentals of Qt The Story of Qt 10/28

Page 11: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Module: Fundamentals of Qt

The Story of QtDeveloping a Hello World ApplicationHello World using Qt CreatorPractical Tips for Developers

Fundamentals of Qt Developing a Hello World Application 11/28

Page 12: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

“Hello World” in Qt

// main.cpp

#include <QtGui>

int main(int argc, char *argv[]){QApplication app(argc, argv);QPushButton button("Hello world");button.show();return app.exec();

}

• Program consists of• main.cpp - application code• helloworld.pro - project file

Demo fundamentals/ex-helloworld

Fundamentals of Qt Developing a Hello World Application 12/28

Page 13: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Project File - helloworld.pro

• helloworld.pro file• lists source and header files• provides project configuration

# File: helloworld.proSOURCES = main.cppHEADERS += # No headers used

• Assignment to variables• Possible operators =, +=, -=

See qmake tutorial Documentation

Fundamentals of Qt Developing a Hello World Application 13/28

Page 14: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Using qmake

• qmake tool• Creates cross-platform make-files

• Build project using qmakecd helloworldqmake helloworld.pro # creates Makefilemake # compiles and links application./helloworld # executes application

• Tip: qmake -project• Creates default project file based on directory content

See qmake Manual Documentation

Qt Creator does it all for you

Fundamentals of Qt Developing a Hello World Application 14/28

Page 15: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Module: Fundamentals of Qt

The Story of QtDeveloping a Hello World ApplicationHello World using Qt CreatorPractical Tips for Developers

Fundamentals of Qt Hello World using Qt Creator 15/28

Page 16: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

QtCreator IDE

• Advanced C++ code editor• Integrated GUI layout and forms designer• Project and build management tools• Integrated, context-sensitive help system• Visual debugger• Rapid code navigation tools• Supports

multipleplatforms

Fundamentals of Qt Hello World using Qt Creator 16/28

Page 17: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Overview of Qt Creator Components

See Creator Quick Tour Documentation

Fundamentals of Qt Hello World using Qt Creator 17/28

Page 18: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Finding Code -Locator

• Click on Locator or press Ctrl+K (Mac OS X: Cmd+K)• Type in the file name• Press Return

Locator Prefixes• : <class name> - Go to a symbol definition• l <line number> - Go to a line in the current document• ? <help topic> - Go to a help topic• o <open document> - Go to an opened document

See Navigating Around Your Code with Locator Documentation

Fundamentals of Qt Hello World using Qt Creator 18/28

Page 19: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Debugging an Application

• Debug −> Start Debugging (or F5)

See Qt Creator and Debugging Documentation

Fundamentals of Qt Hello World using Qt Creator 19/28

Page 20: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Qt Creator Demo "Hello World"

What we’ll show:• Creation

of an empty Qt project• Adding themain.cpp source file

• Writing of theQt Hello World Code• Showing Locator Features

• Running the application• Debugging

the application• Looking up the text property of our button

• There is more to Qt CreatorSee Qt Creator Manual Documentation

Fundamentals of Qt Hello World using Qt Creator 20/28

Page 21: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Module: Fundamentals of Qt

The Story of QtDeveloping a Hello World ApplicationHello World using Qt CreatorPractical Tips for Developers

Fundamentals of Qt Practical Tips for Developers 21/28

Page 22: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

How much C++ do you need to know?

• Objects and classes• Declaring a class, inheritance, calling member functions etc.

• Polymorphism• That is virtual methods

• Operator overloading• Templates

• For the container classes only• No ...

• ... RTTI• ... sophisticated templates• ... exceptions thrown• ...

Fundamentals of Qt Practical Tips for Developers 22/28

Page 23: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Qt Documentation• Reference Documentation

• All classes documented• Contains tons of examples

• Collection of Howto’s and Overviews• A set of Tutorials for Learners

Fundamentals of Qt Practical Tips for Developers 23/28

Page 24: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Finding the Answers

• Documentation in Qt Assistant (or QtCreator)• Qt’s examples: $QTDIR/examples• Qt developer network: http://developer.qt.nokia.com/• Qt Centre Forum: http://www.qtcentre.org/• KDE project source code

• http://lxr.kde.org/ (cross-referenced).• Mailing lists see http://qt.nokia.com/lists• IRC:

• On irc.freenode.org channel: #qt

Use the source!Qt’s source code is easy to read, and can answer questions thereference manual cannot answer!

Fundamentals of Qt Practical Tips for Developers 24/28

Page 25: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Modules and Include files• Qt Modules

• QtCore, QtGui, QtXml, QtSql, QtNetwork, QtTest ...See Qt Modules Documentation

• Enable Qt Module in qmake .pro file:• QT += network

• Default: qmake projects use QtCore and QtGui• Any Qt class has a header file.

#include <QLabel>#include <QtGui/QLabel>

• Any Qt Module has a header file.#include <QtGui>

Fundamentals of Qt Practical Tips for Developers 25/28

Page 26: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Includes and Compilation Time

Module includes#include <QtGui>

• Precompiled header and the compiler• If not supported may add extra compile time• If supported may speed up compilation• Supported on: Windows, Mac OS X, Unix

See qmake precompiled headers Documentation

Class includes#include <QLabel>

• Reduce compilation time• Use class includes (#include <QLabel>)• Forward declarations (class QLabel;)

Place module includes before other includes.

Fundamentals of Qt Practical Tips for Developers 26/28

Page 27: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Questions And Answers

• What is Qt?• Which code lines do you need for a minimal Qt application?• What is a .pro file?• What is qmake, and when is it a good idea to use it?• What is a Qt module and how to enable it in your project?• How can you include a QLabel from the QtGui module?• Name places where you can find answers about Qt problems

Fundamentals of Qt Practical Tips for Developers 27/28

Page 28: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Questions And Answers

• What is Qt?• Which code lines do you need for a minimal Qt application?• What is a .pro file?• What is qmake, and when is it a good idea to use it?• What is a Qt module and how to enable it in your project?• How can you include a QLabel from the QtGui module?• Name places where you can find answers about Qt problems

Fundamentals of Qt Practical Tips for Developers 27/28

Page 29: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Questions And Answers

• What is Qt?• Which code lines do you need for a minimal Qt application?• What is a .pro file?• What is qmake, and when is it a good idea to use it?• What is a Qt module and how to enable it in your project?• How can you include a QLabel from the QtGui module?• Name places where you can find answers about Qt problems

Fundamentals of Qt Practical Tips for Developers 27/28

Page 30: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Questions And Answers

• What is Qt?• Which code lines do you need for a minimal Qt application?• What is a .pro file?• What is qmake, and when is it a good idea to use it?• What is a Qt module and how to enable it in your project?• How can you include a QLabel from the QtGui module?• Name places where you can find answers about Qt problems

Fundamentals of Qt Practical Tips for Developers 27/28

Page 31: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Questions And Answers

• What is Qt?• Which code lines do you need for a minimal Qt application?• What is a .pro file?• What is qmake, and when is it a good idea to use it?• What is a Qt module and how to enable it in your project?• How can you include a QLabel from the QtGui module?• Name places where you can find answers about Qt problems

Fundamentals of Qt Practical Tips for Developers 27/28

Page 32: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Questions And Answers

• What is Qt?• Which code lines do you need for a minimal Qt application?• What is a .pro file?• What is qmake, and when is it a good idea to use it?• What is a Qt module and how to enable it in your project?• How can you include a QLabel from the QtGui module?• Name places where you can find answers about Qt problems

Fundamentals of Qt Practical Tips for Developers 27/28

Page 33: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

Questions And Answers

• What is Qt?• Which code lines do you need for a minimal Qt application?• What is a .pro file?• What is qmake, and when is it a good idea to use it?• What is a Qt module and how to enable it in your project?• How can you include a QLabel from the QtGui module?• Name places where you can find answers about Qt problems

Fundamentals of Qt Practical Tips for Developers 27/28

Page 34: Produced by Nokia, Qt Development Frameworks · See qmake tutorial Documentation Fundamentals of Qt Developing a Hello World Application 13/28. Using qmake qmake tool Creates cross-platform

c© 2010 Nokia Corporation and its Subsidiary(-ies).

The enclosed Qt Training Materials are provided under the CreativeCommons Attribution ShareAlike 2.5 License Agreement.

The full license text is available here:http://creativecommons.org/licenses/by-sa/2.5/legalcode

Nokia, Qt and the Nokia and Qt logos are the registered trademarks ofNokia Corporation in Finland and other countries worldwide.

Fundamentals of Qt Legal 28/28


Recommended