对Qt / C ++类公共静态成员的未定义引用

时间:2015-08-18 08:26:58

标签: c++ qt

我有以下课程:

Managed (v4.5, v4.0) code, Native code

及其实施:

#ifndef UEPEOPLEMODEL_H
#define UEPEOPLEMODEL_H

#include <QImage>
#include <QVariant>
#include <QStringList>
#include <QDebug>
#include <QHash>
#include <QByteArray>
#include <QtSql/QSqlError>
#include <QtSql/QSqlQueryModel>
#include <QtSql/QSqlRecord>
#include <QModelIndex>
#include <QQuickImageProvider>
#include <QHash>
#include <QByteArray>

#include "../settings/uedefaults.h"

class UePeopleModel : public QSqlQueryModel, QQuickImageProvider
{
    Q_OBJECT

public:
    UePeopleModel(QObject *parent=0);
    ~UePeopleModel();

    QVariant data(const QModelIndex &index,
                  int role) const Q_DECL_OVERRIDE;
    QImage image(const QString &id) const;
    QImage requestImage(const QString &id,
                        QSize *size,
                        const QSize &requestedSize);
    QHash<int, QByteArray> roleNames() const;

public:
    static const int UePersonNameRole=Qt::UserRole+1;
    static const int UePersonImageRole=UePersonNameRole+1;
};

#endif // UEPEOPLEMODEL_H

现在,如果我尝试构建项目,我会收到以下错误:

  

uepeoplemodel.o:在函数#include "uepeoplemodel.h" UePeopleModel::UePeopleModel(QObject* parent) : QSqlQueryModel(parent), QQuickImageProvider(QQmlImageProviderBase::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading) { QSqlDatabase db; if(!QSqlDatabase::connectionNames().contains(UePosDatabase::UeDatabaseConnectionNames::DATABASE_CONNECTION_NAME_PEOPLE, Qt::CaseInsensitive)) { db=QSqlDatabase::addDatabase(UePosDatabase::DATABASE_DRIVER, UePosDatabase::UeDatabaseConnectionNames::DATABASE_CONNECTION_NAME_PEOPLE); } // if db.setHostName(/*this->uePosSettings()->ueDbHostname()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_HOSTNAME); db.setDatabaseName(/*this->uePosSettings()->ueDbName()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_NAME); db.setUserName(/*this->uePosSettings()->ueDbUser()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_USERNAME); db.setPassword(/*this->uePosSettings()->ueDbPassword()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_PASSWORD); if(db.open()) { this->setQuery(UePosDatabase::UeSqlQueries::UeTablePeople::SQL_QUERY_GET_ALL_PEOPLE, db); } else { qDebug() << db.lastError().text(); } } // default constructor UePeopleModel::~UePeopleModel() { } // default destructor QVariant UePeopleModel::data(const QModelIndex &index, int role) const { QVariant value=QSqlQueryModel::data(index, role); if(value.isValid()) { switch(role) { case UePeopleModel::UePersonNameRole: { return value.toString(); } // case case UePeopleModel::UePersonImageRole: { return QString::number(index.row()); } // case default: value=QVariant(); } // switch } // if return value; } // data QImage UePeopleModel::image(const QString &id) const { int iRow=id.toInt(); } // image QImage UePeopleModel::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { QImage image=this->image(id); *size = image.size(); return image; } // requestImage QHash<int, QByteArray> UePeopleModel::roleNames() const { QHash<int, QByteArray> roles; roles.clear(); roles.insert(UePeopleModel::UePersonNameRole, "UePeopleModel::UePersonNameRole"); roles.insert(UePeopleModel::UePersonImageRole, "UePeopleModel::UePersonNameRole"); return roles; } // roleNames UePeopleModel :: UePersonNameRole&#39;   /home/markofr/projects/build-ueBlagajnaClient-Desktop_Qt_5_5_0_GCC_64bit-Debug/../ueBlagajnaClient/database/uepeoplemodel.cpp:88:   未定义的引用`UePeopleModel :: UePersonImageRole&#39;   Makefile:234:目标&#39; ueBlagajnaClient&#39;的配方collect2失败:   错误:ld返回1退出状态make:*** [ueBlagajnaClient]错误1   10:22:57:过程&#34; / usr / bin / make&#34;退出代码2.错误时   构建/部署项目ueBlagajnaClient(套件:Desktop Qt 5.5.0 GCC   64位)

UePeopleModel::roleNames() const': /home/markofr/projects/build-ueBlagajnaClient-Desktop_Qt_5_5_0_GCC_64bit-Debug/../ueBlagajnaClient/database/uepeoplemodel.cpp:86: undefined reference toUePeopleModel::UePersonNameRole在头文件中声明为public static int UePeopleModel::UePersonImageRole roles.insert(). Why am I getting this error? The error pops up int roleNames()`method。

0 个答案:

没有答案