0

我是黑莓开发的初学者。我正在创建一个简单的 Person 类,其中包含 .cpp 和 .hpp 文件,其中 firstName、customerId、address 作为类的成员。我已经创建了 Properties 和 setter、getters,但它在 Person.cpp 中给出了错误,设置器定义,当我尝试发出在 Person.hpp 中声明的信号时。

错误:未定义对“Person::customerIDChanged(QString const&)”的引用

个人.cpp:

void Person::setCustomerID(const QString &newId)
{
    if (newId != m_id) {
        m_id = newId;
        emit customerIDChanged(newId); // gives error at this line
    }
}

void Person::setFirstName(const QString &newName)
{
    if (newName != m_firstName) {
        m_firstName = newName;
        emit firstNameChanged(newName);// gives error at this line
                }
}
void Person::setAddress(const QString &newName){

if (newName != m_address) {
 m_address = newName;
 emit addressChanged(m_address);// gives error at this line
   }}

人.hpp:

class Person:public QObject
{ 
    Q_OBJECT

Q_PROPERTY( QString customerID READ customerID WRITE setCustomerID NOTIFY customerIDChanged FINAL)

   Q_PROPERTY( QString firstName READ firstName WRITE setFirstName NOTIFY firstNameChanged FINAL)

   Q_PROPERTY( QString address READ address WRITE setAddress NOTIFY addressChanged FINAL)

public:

  Person(QObject *parent = 0): QObject(parent){};

  Person(const QString &id, const QString &firstname, const QString &address, QObject *parent = 0) : QObject(parent)
   , m_id(id)
   , m_firstName(firstname)
   , m_address(address){};

  QString customerID() const;
  QString firstName() const;
  QString address() const;

  void setCustomerID(const QString &newId);
  void setFirstName(const QString &newName);
  void setAddress(const QString &newName);

Q_SIGNALS:

void customerIDChanged(const QString &newId);
void firstNameChanged(const QString &firstName);
void addressChanged(const QString &address);

private:

    QString m_id;
    QString m_firstName;
    QString m_address;};
#endif

提前谢谢!!

4

0 回答 0