【问题标题】:error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class QList'错误:'template<class T> class QList' 的模板参数列表中的参数 1 的类型/值不匹配
【发布时间】:2015-10-29 17:37:30
【问题描述】:

我正在尝试使用 QList 并在编译时出现错误! 这是我的代码:

class Right
{
public:
    Right();
    Right(const Right& other);
    Right(RightName name, QDate validity_date);

    bool isValid() const;
    bool operator==(const Right& other)const;
    Right &operator=(const Right &other);
    QString name;
    QDate expiryDate;
};

然后在 QList 中使用此 Right

class FileRightsRepo
{
public:
    FileRightsRepo(QString rightsPath);
    ~FileRightsRepo() { }
    // IRightsRepo interface
     QList<Right> getRights();

private:
    QString _rightsPath; // PATH to the file containing rights
};

我已经实现了这些类,但是当我尝试编译时,我得到了以下异常:

error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class QSet'
  QList<Right> getRights();

getRights() 的返回类型是什么。 我已经阅读了 Qt 文档,它指定要使用的对象是可分配的类型,并且我已经实现了所需的功能。

提前感谢您的帮助:)

【问题讨论】:

  • 为什么错误是关于 QSet 的?您确定代码与错误对应吗?

标签: c++ qt qlist


【解决方案1】:

这意味着您在其他地方将Right 定义为变量、枚举常量或类似内容。例如,这是一个重现您的问题的测试用例:

class Right;
enum { Right };
QList<Right> getRights();

你可以确保你使用的类如下

QList<class Right> getRights();

虽然最好使用 IDE 或 something else 追踪 Right 的其他定义并修复问题的根源。

【讨论】:

  • 确实,类一开始是正确的,但后来我使用 Qt Creator 对其进行了重构以将其命名为 Right,但显然它重构了 Q_CORE_EXPORT QTextStream &right(QTextStream &s);在 qstreamtext.h 中!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多