3. Implementation of C++ Classes in Qt6: Inheritance, Interface, and QObject

Опубликовано: 19 Июнь 2026
на канале: Free Tutorial TV
304
4

00:00 Constructors and Destructors
14:19 Inheritance
29:19 Interface
40:56 Overriding
53:00 Q Object Class
58: Age Calculator App

In this video, we explore how to implement C++ classes within the Qt6 framework, focusing on essential object-oriented programming concepts like inheritance, interfaces, and the QObject class. We'll demonstrate:

How to create base and derived classes in Qt6.
Implementing interfaces using Qt's specific features.
Understanding and utilizing QObject for signal-slot communication. This tutorial is perfect for developers familiar with C++ who want to deepen their understanding of Qt6 development and how it handles class hierarchies and interfaces.

Make sure to like, subscribe, and click the bell icon for more tutorials on C++ and Qt6 development!


This video is going to talk about constructor's and de-constructor's, why?

Because we want to talk about the object Life-cycle this is not specific to cute.

This is a C++ thing, actually.

Most programming languages have a concept of a constructor and a de constructor.

However, what we want to talk about is the object lifecycle from the perspective of cute.

And remember, we talked that cute object does not like to be copied.

So we have to handle things a little bit carefully here.

So let's go ahead and right click add new and we're going to make a class.

And now that we've done this one, I'm going to go through this a little bit faster.

Each time I may even start videos with classes or any pre made, we'll say a laptop.

From here, what we want to do is take a base class and remember, it's going to include Q object

and add that macro.

Inheritance is, well, a complex topic, but to clarify, it's a class that gains the members of their

base.

Think of it this way.

For example, let's say we have a base class called person, it's a very well boring class.

It doesn't have any air, color, skin tone, gender, age or anything like that.

It just represents a person.

Using inheritance, we can create a number of different classes, for example, we can create a class

called Mark in a class called Jane.

They are two totally different classes, but at their base, they're both people.

They both inherit the person class.

This video is going to talk about class inheritance, and this is arguably one of the more challenging

aspects of C++ to really wrap your head around, we're going to try and make it super simple, but I'm

going to have to defer to my notes several times just because we are talking about a complex topic here.

So, for example, let's say we have a square, a humble little square sitting out in the world doing

its own thing.

And let's give this a nice green color here and let's say we want to inherit that, but we want to change

it slightly.

So it's going to be kind of like this.

In the last video, we talked about multiple inheritance and how you're going to get ambiguous name

and all sorts of other crazy errors and that there's a better way of doing it.

Now, there are many, many ways of doing this, but I'm going to show you what I believe is the best

way, which is interfaces.

So what is an interface?

Well, it's a contract between objects.

Think of that.

It's a contract that's saying that you an object will include some sort of thing, whatever it is.

Let's take a visual representation here.

So here we have inheritance.

What we're going to talk about next is overwriting, and it's a little bit complex and a lot of people

like to spend a long, long time talking about this, we're going to overly simplify this because,

again, this is, of course, on programming and we're going to teach you just enough C++ to get by.

So overriding what really is it and why do we need it?

Well, we want to change the behavior of a base class.

Let me explain here.

So we've got a queue object and we are inheriting that from a flying class.

We're adding a function called speak.

We are now making a lie in class, which inherits feline, which means it also inherits Kuis object,

and the lion has another function called speak.

How do we know which one of these speaks being called, because as we've seen in the past, if we create

One thing that often mystifies newcomers as well, you object itself, it's the base class for, well,

pretty much every cute class, I say pretty much because when we get into more advanced topics like

generics and templating and things like that, cute object, as you've seen, does not like to be copied.

So it doesn't play well.

Therefore, it's not all it's moss.

But let's take a deeper look at cute object here.

So I'm just going to, you know, let's right click here, add new.

We've done this before.

You're not seeing anything brand new, but I just wanted to slow this way down here.

So base class, we've kind of taken this list for granted.

Custom, yes, you can do whatever you want, but we've been saying you object and notice it smart enough

to say include queue object and add the queue object macro.