Professional Documents
Culture Documents
A slot
must be implemented in the class
can be invoked as a member function
on a object of the class
A signal
does not have an implementation
cannot be invoked as a member
function
Product implementation
#ifndef PRODUCT_H
#define PRODUCT_H
#include <QString>
Product::Product(QString d,
int n):description(d), num(n)
{}
class Product{
public:
Product(QString d, int n);
void sell(int n);
private:
QString description;
int num;
};
#endif
Product implementation
Product::Product(QString d,
int n):description(d), num(n)
{}
void Product::sell(int n){
if(n <= num)
num = num n;
if (num == 0)
emit restock(description);
}
OrderList implementation
QStringList OrderList::getList()
const{
return descriptions;
}
void OrderList::add(QString d){
descriptions.append(d);
}
OrderList implementation
QStringList OrderList::getList()
const{
return descriptions;
}
void OrderList::add(QString d){
descriptions.append(d);
}
Reflection on Example 1
Signals and
program
slots
in
non-GUI
Next
We will
see how to use signals and slots in a
GUI program
use signals and slots from the existing
Qt classes
should
generate
the
QLabel
QVBoxLayout
QLineEdit
QPushButton
QWidget
Reflection on Example 2
Signals and slots in a GUI program
Used signals and slots that already
exist in Qt classes
Summary
This presentation
explained object to object
communication in Qt using signals
and slots
contains simple examples that should
help you understand the basics of
signals and slots
Way Forward..