C++ Programming By Example
Section 1: Introduction to C++ and Qt
In this section, we introduce C++ and Qt and get the development environment set up for the course.
The Course Overview
Why C++?
Setting Up Your Development Environment
Basic C++ Syntax
Installing Qt5 on Windows
1.1 The Course Overview
This video provides an overview of the entire course.
1.2 Why C++?
Why should you use C++ in 2018? Is the language still useful?
Identify how C++ is used today
Compare the advantages that C++ has over other languages
Analyze the particular reasons for using C++
1.3 Setting Up Your Development Environment
How do you set up a C++ development environment on Windows 10?
Download and install Visual Studio
Download and install CMake
Test with a small check
1.4 Basic C++ Syntax
What is the basic C++ language “grammar”?
Identify the primitive integer types
Understand primitive floating-point types
Know how to control the code execution flow
1.5 Installing Qt5 on Windows
How do you install Qt5 on Windows 10?
Download installer from the web
Run installer
Select the correct items in installer to install
Section 2: Building a Virtual Die with C++
In this section, we build our first C++ application: a virtual die.
Setting Up Your First C++ Project
Coding a Virtual Die – Generating Random Numbers
Coding a Virtual Die – Displaying the Output
Enhancing the Virtual Die with User Input
2.1 Setting Up Your First C++ Project
How to use the course source code?
Obtain the source code
Open CMake and open source directory in CMake
Configure the project via CMake and then generate the solution
2.2 Coding a Virtual Die – Generating Random Numbers
How do you generate random numbers in C++?
Introduce cppreference for C++ documentation
Understand probability distributions and which one is appropriate for a die
Use the classes available in the C++ standard template library to generate a random number
2.3 Coding a Virtual Die – Displaying the Output
How to display formatted output to the user?
Know printf() via cppreference
Use printf() to show formatted statements
Implement different placeholders to print different values
2.4 Enhancing the Virtual Die with User Input
How to get input from the user and use it in the virtual die?
Introduce std::cin
Show a brief example of using std::cin
Allow viewers to implement the coding exercise to get user input on die range and number of
rolls
Section 3: Data Structures and Algorithms: Building a Sorting Application
Here we get into the bread and butter of C++: containers and algorithms. C++ is designed to be generic
and flexible, and here you’ll get to see that first hand. We’ll begin with an overview of some of the
available containers in the Standard Template Library.
Overview of Containers in C++
A Deeper Dive into std::vector
Overview of STL Algorithms
Use STL Algorithms with Containers
Building a Sorting Application
3.1 Overview of Containers in C++
What are the available containers for storing data in C++?
Look at cppreference on available container classes
Code small examples on how to use containers
Run samples and observe the output to understand how the containers work
3.2 A Deeper Dive into std::vector
What is the proper use of std::vector?
Analyze cppreference to show nuances of using std::vector
Show the difference between push_back and emplace_back
Understand the “proper” ways to initialize a std::vector
3.3 Overview of STL Algorithms
What algorithms are available in the standard template library?
Introduce algorithms available in the standard template library via the documentation
Implement examples of use of the various algorithms
Show the output from program runs using the STL algorithms
3.4 Use STL Algorithms with Containers
How do you use STL algorithms with C++ containers?
Explain iterators
Show examples to further illustrate how they work
Analyze the results of the examples via print statements
3.5 Building a Sorting Application
How to build a mini address book that is sortable by first name, last name, and phone number?
Introduce std::pair and std::tuple
Create fake data for “phone book”
Show how to use the std::sort function to sort by first name, last name, and phone number
Section 4: Classes and Structures: Building a Casino Guessing Game
In this section, you’ll learn about classes and structures in C++ and use them to organize your code. We’ll
put this into practice by building a casino-style guessing game.
Why Use Classes and Structures?
Overview of Classes and Structures
Differences Between Classes and Structures
Implementing a Casino Guessing Game
4.1 Why Use Classes and Structures?
Why should you bother about classes/structures in C++?
Learn to design code logically
Understand how to re-use code
Encapsulate ideas/models in code
4.2 Overview of Classes and Structures
How do you use/declare classes and structures in C++?
Use the ‘class’ and ‘struct’ keywords
Analyze { and }; to define where a class begins/ends
Implement access modifiers such as ‘public’, ‘private’, and ‘protected’
4.3 Differences Between Classes and Structures
What is the difference between a class and a structure?
Understand that they basically do the same thing
Default access modifier for classes is private. For structures, it’s public
Structures are still around to preserve C compatibility
4.4 Implementing a Casino Guessing Game
How can you use classes/structures to make a game?
Think of the parts of the game
Imagine what each class in the game should do
Implement the game and play
Section 5: Building a Library Management System
You’ll get to put everything you’ve learned together to build a custom library management system.
Planning out an Application
Building a Library Management System
Adding Test Data
Adding Search Functionality
5.1 Planning out an Application
How to structure and plan an application?
Identify key parts of the application
Plan out the class structure using class diagrams (UML)
Create a class implementation using UML diagrams
5.2 Building a Library Management System
How to build a library management system (books)?
Plan out the classes
Implement the classes based on the plan
Compare functions for basic functionality in the application
5.3 Adding Test Data
How to add test data to the application?
Define basic data in code
Add a test .csv file with fake data
Edit the .csv file to see how the library works
5.4 Adding Search Functionality
How can you add search functionality to the application?
Learn what algorithms could be used from the STL
Implement search by book title
Experiment with search by author
Section 6: Getting Acquainted with Qt
Here you’ll get a basic GUI application setup and running to get acquainted with Qt5.
Setting Up Your First GUI Project
Setting Up a Basic GUI with Qt Creator
Running Your First GUI Application
6.1 Setting Up Your First GUI Project
How do you use CMake to set up a GUI project?
Install Qt5
Implement CMake for your Qt5 directory as shown in the video
Reconfigure and generate the project via CMake
6.2 Setting Up a Basic GUI with Qt Creator
How can you add UI elements to your GUI application?
Open Qt Creator
Create a new Qt class
Add the files to the correct folders in the course code
6.3 Running Your First GUI Application
In what ways can you run your GUI application?
Run the app through Visual Studio
Run the app through PowerShell
Run the app through File Explorer
Section 7: Qt Signals and Slots: Building a Text Editor
You will get acquainted with Qt5 further by using signals and slots to create a reactive UI.
Setting Up Your Text Editor Project
Creating a Basic GUI in Qt Creator
Reacting to User Interaction with Signals and Slots
Creating Custom Slots
Finishing the Text Editor
7.1 Setting Up Your Text Editor Project
How do you use CMake to set up a GUI project?
Use the basic project setup provided by instructor
Open Qt Creator and created the needed files as shown
Put the files in the correct folders
7.2 Creating a Basic GUI in Qt Creator
How to use Qt Creator to make a basic GUI?
Open the *.ui file in Qt Creator
Add the QPlainTextEdit widget to the UI
Arrange the layout contents vertically and add menu items
7.3 Reacting to User Interaction with Signals and Slots
What are signals and slots in Qt?
Go through the Qt documentation
Understand that signals get emitted when something happens
Learn that slots can be “connected” to signals to react to events
7.4 Creating Custom Slots
How do you write your own slots?
Use access modifier “public” + keyword “slots”
Implement the function declaration like any other class method
Define the implementation like any other class method
7.5 Finishing the Text Editor
How do you save the file on the system and open the same on the system later?
Remove unnecessary signal and slot connections
Allow for saving the text file to anywhere on the system
Open any text file on the computer
Section 8: Building a Painting Application in Qt5
In this section, you’ll get a taste of some of the more advanced Qt topics, including building your own
custom Qt5 widget.
Setting Up Your Painting Application
Understanding Qt5 Widgets
Creating Your Own Qt5 Widget
Reacting to User Input
Painting User Input on Screen
Adding the Ability to Draw Circles
Allow for Shape Resizing
8.1 Setting Up Your Painting Application
How to set up a basic application?
Use basic project setup provided by instructor
Open Qt Creator and created needed files as shown
Put the files in the correct folders
8.2 Understanding Qt5 Widgets
How do Qt5 widgets work under the hood?
Look at the Qt5 documentation
Understand that Qt widgets are “painted”
Understand that Qt5 widgets use painters to “paint” their content
8.3 Creating Your Own Qt5 Widget
How do you create your own Qt5 widget?
Look at the Qt documentation
Inherit from QWidget
Override parent methods that we need in the class
8.4 Reacting to User Input
How can we react to user input in our custom widget?
Look at the Qt documentation
Override mouse event functions
Print data to the console to confirm that the app is reacting properly
8.5 Painting User Input on Screen
How can we paint user input on the screen?
Introduce the QPainterPath class along with QPainter
Update the list of paths in the widget and draw them
Update the current path as the user uses the widget
8.6 Adding the Ability to Draw Circles
How can we add the ability to draw shapes?
Look at the QPainterPath documentation
Change drawing style on a custom widget based on user selection
Use the ‘addEllipse’ and ‘addRect’ functions
8.7 Allow for Shape Resizing
How can we allow for shapes to be resized as they’re drawn?
Demo of what the result should look like
Create simple structs to model a circle and square
Use QPainter directly to update the widget when drawing shapes