0% found this document useful (0 votes)
17 views

Suba C++ and Qt

Uploaded by

Suba S M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Suba C++ and Qt

Uploaded by

Suba S M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

PROGRAMMING IN MODERN C++

&
QT CREATOR

SUBA S M
PROGRAMMING IN MODERN
C++
INTRODUCTION TO
C++
C++ Overview: C++ is a general-purpose programming language derived from C,
designed for system and application programming, emphasizing performance,
efficiency, and flexibility.
Object-Oriented: C++ supports object-oriented programming paradigms, allowing for
the creation of reusable code components called objects, which encapsulate data and
behavior.
Syntax: C++ syntax is similar to C but includes additional features like classes,
templates, and operator overloading, providing more expressive power and abstraction.
Standard Template Library (STL): C++ comes with a rich standard library known as
the STL, providing a set of reusable algorithms and data structures like vectors, lists, and
maps, enhancing productivity and code quality.
Platform Independence: C++ programs can be compiled to run on various platforms,
including Windows, Linux, and macOS, ensuring cross-platform compatibility and
flexibility in deployment.
Arrays in C++

• An array is a fixed-size collection of elements of the same


data type stored in contiguous memory locations.

• Syntax

int arr [5]; //Declaration of array

int arr [5] = {1, 2, 3, 4, 5};


Strings
In C++, a string is a sequence of characters stored as a single data type. It's often
used to represent textual data.
Declaration and Initialization:
You can declare and initialize strings using double quotes.
std::string greeting = "Hello, world!";
Accessing Characters:
You can access individual characters in a string using the array syntax ([]) or the at()
method:
char c1= arr[0]; // Accessing the first character
char c2= arr.at(4); // Accessing the fifth character
STACK IN C++
In c++, a stack is a data structure that follows the last in, first out (lifo) principle,
meaning the last element added to the stack is the first one to be removed.

DECLARATION AND INITIALIZATION:


To use a stack in c++, you typically include the <stack> header file and declare an
instance of the std::stack template class, specifying the type of elements it will
contain.
#include <stack>
std::stack<int> myStack;

PUSH OPERATION:
Elements can be added to the top of the stack using the push() method.
myStack.push(5);

Pop Operation:
The pop() method removes the top element from the stack.
REFERENCE AND POINTER​
Reference Pointer

Reference: Pointer:
A reference variable is a "reference" to A pointer is a variable that stores
an existing variable, and it is created with the memory address of another variable.
the & operator: Pointers allow indirect access to memory
Syntax; locations, enabling manipulation of data and
int x = 10; dynamic memory allocation.
int & ref = x; // ref is a reference to x Syntax;
int x = 10;
int* ptr = &x; // Initializes ptr with the
address of x
CLASSES AND OBJECTS​

Classes:
It is a user-defined data type, which holds its own data members and
member functions, which can be accessed and used by creating an instance of that
class​
A C++ class is like a blueprint for an object.​

Objects:​
An object in C++ is an instance of a class.
When class is define, no memory is allocated but when an (object is
created ) memory is allocated.​
FUNCTION OVERLOADING
Allows you to define multiple functions with the same name but different parameter lists. this means you can have
multiple functions with the same name, but each function performs a different task based on the parameters it receives.
Example code
#include <iostream>
int add(int a, int b) {
return a + b;}
int add(int a, int b, int c) {
return a + b + c;
}
int main() {
std::cout << "Sum of 5 and 7: " << add(5, 7) << std::endl;
std::cout << "Sum of 3, 4, and 6: " << add(3, 4, 6) << std::endl;
return 0;
ACCESS SPECIFIERS

PUBLIC PRIVATE

• Public members are accessible from outside the class.


• Private members are accessible only within the same
class.

• They can be accessed by any code that can see the • They cannot be accessed directly from outside the
class. class.

• Useful for interface methods and attributes. • Helps in hiding implementation details.

• Encourages data hiding and information hiding.


• Facilitates encapsulation and abstraction.
PROTECTED
▪ Protected members are accessible within the class and its subclasses (derived
classes).

▪ They are not accessible from outside the class hierarchy.

▪ Used when you want derived classes to have access but not other classes.
CONSTRUCTOR
TYPES OF CONSTRUCTOR
✓ DEFAULT
✓ PARAMETERISED
✓ COPY
Default Constructor:
Automatically invoked when an object is created without any arguments.
Initializes data members to default values or performs any necessary setup.
Example: MyClass() {}

Parameterized Constructor:
Accepts arguments during object creation to initialize data members.
Allows customization of object initialization based on provided values.
Example: MyClass(int value) { data = value; }

Copy Constructor:
Creates a new object as a copy of an existing object.
Copies data members of the source object to the new object.
Example: MyClass(const MyClass& other) { data = other.data; }
Introduction of QT creator

• Qt Creator is like a special toolbox for building computer


programs.
• It's designed especially for making apps using Qt, which is a
set of tools for creating all sorts of software.
• With Qt Creator, you get everything you need in one place:
a place to write your code, tools to help you design what
your app will look like, and ways to test and fix any
problems.
• It's like having a workshop where you can build your apps
from start to finish.
The Qt is used for developing
graphical user interface and multi-
Uses of QT creator platform applications that run on all
major desktop platforms and mobile
or embedded platforms.

The Qt framework contains a


comprehensive set of highly intuitive
and modularized C++ library classes
and is loaded with APIs to simplify
your application development
Modules for Qt creator

• QT Designers
• Qt Gui tools
• QT Helps
• Qt Test
QT Designers
• Qt Designer enables you to quickly build the GUI of your main
windows using the predefined Main Window template.
• Once you've created a form based on that template, you'll have
tools to perform the following actions: Creating a main menu.
• Adding and populating toolbars.
QT Gui tools

• Qt is used for developing graphical user interfaces


(GUIs) and multi-platform applications that run on all
major desktop platforms and mobile or embedded
platforms.
• Most GUI programs created with Qt have a native-
looking interface, in which case Qt is classified as a
widget toolkit.
WIDGETS

• Visible user interface component


• Shorthand for window gadget
• Buttons, menu, frames, sliders, are all
widget
• Widget can contain other widgets
Q widget
• The Q Widget class is the base class of all user interface
objects.
• The widget is the atom of the user interface: it receives
mouse, keyboard and other events from the window
system, and paints a representation of itself on the
screen.
• Every widget is rectangular, and they are sorted in a Z-
order.
LAYOUTS

In Qt, layout management is essential for creating


user interfaces that adapt to different screen sizes
and orientations. Qt provides a variety of layout
classes like QVBoxLayout, QHBoxLayout, and
QGridLayout, which allow widgets to be organized
in a flexible and dynamic manner. These layouts
automatically adjust the position and size of
widgets within a window or widget container,
ensuring proper alignment and spacing.
QRADIO
BUTTON

In Qt, a QRadioButton is a GUI widget used


to present an exclusive choice to the user
within a group of options. It allows users to
select a single option from a set of mutually
exclusive choices. When one radio button is
selected, the previously selected one is
automatically deselected. QRadioButtons are
often used in conjunction with other widgets,
such as QGroupBox or QVBoxLayout, to
organize and display options neatly within a
user interface.
QSTATUS BAR

QStatusBar in Qt is a widget used to display


status information and short messages to the
user. It typically resides at the bottom of a
QMainWindow. It supports text, icons, and
custom widgets, providing a versatile way to
communicate application status. Developers can
dynamically update the content of the
QStatusBar to reflect changes or events in the
application.
THANK YOU

You might also like