#2
h3wardt2011-11-01 04:36
|
程序代码:
#include
#include
using std::cout;
using std::endl;
class Employee : public QObject
{
Q_OBJECT
public:
Employee(int);
int getSalary() const;
signals:
void salaryChanged(int);
public slots:
void setSalary(int);
private:
int salary;
};
Employee::Employee(int salary)
{
this->salary = salary;
connect(this,SIGNAL(salaryChanged(int)),this,SLOT(setSalary(int)));
}
int Employee::getSalary() const
{
return salary;
}
void Employee::setSalary(int newSalary)
{
if(newSalary != salary)
{
salary = newSalary;
emit salaryChanged(newSalary);
}
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Employee e(3200);
e.setSalary(4500);
return a.exec();
}
编译结果如下:#include
using std::cout;
using std::endl;
class Employee : public QObject
{
Q_OBJECT
public:
Employee(int);
int getSalary() const;
signals:
void salaryChanged(int);
public slots:
void setSalary(int);
private:
int salary;
};
Employee::Employee(int salary)
{
this->salary = salary;
connect(this,SIGNAL(salaryChanged(int)),this,SLOT(setSalary(int)));
}
int Employee::getSalary() const
{
return salary;
}
void Employee::setSalary(int newSalary)
{
if(newSalary != salary)
{
salary = newSalary;
emit salaryChanged(newSalary);
}
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Employee e(3200);
e.setSalary(4500);
return a.exec();
}
[local]1[/local]