【问题标题】:error: C2248: 'QVariant::QVariant' : cannot access private member declared in class 'QVariant'错误:C2248:“QVariant::QVariant”:无法访问在“QVariant”类中声明的私有成员
【发布时间】:2016-02-15 03:13:49
【问题描述】:

我在以下行收到意外错误:

MyClass * myObject = new MyClass;

view.rootContext()->setContextProperty("myObject", myObject);

有错误:

error: C2248: 'QVariant::QVariant' : cannot access private member declared in class 'QVariant'

MyClass 只是我编写的一个类,它对QVariant 类没有特别的作用。

【问题讨论】:

    标签: qt qml qt5


    【解决方案1】:

    问题是我忘了从QObject 派生MyClass。它需要派生并在其中定义Q_OBJECT 宏,就像任何QObject 派生类一样。

    【讨论】:

    • 或者,使用正确的方法(工厂建设者):QVariant::fromValue(...)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 2012-11-15
    • 2016-12-02
    • 1970-01-01
    • 2013-07-28
    相关资源
    最近更新 更多