Find root cause of “cannot access private member declared in class 'QObject'”

前端 未结 2 1312
说谎
说谎 2021-01-24 13:34

I understand why I get a C2248: \'QObject::QObject\' : cannot access private member declared in class \'QObject\' . Qt objects are not copyable, as explained here:<

相关标签:
2条回答
  • 2021-01-24 13:43

    The easiest solution to detect the root cause is by making your copy ctor also private. (Or deleted, but that's not possible in VS2010 yet). This will suppress the automatically-generated copy ctor, which was the source of the error.

    0 讨论(0)
  • 2021-01-24 14:01

    If you are not explicitly copying your MyObject but you keep getting this error message then something you're using in conjunction with your MyObject is doing the copying on your behalf.

    The most likely culprit would be one of the container classes, e.g. QList, QVector, etc.

    Read the Container class documentation for more information as well as the specific class' documentation of any container you might be using. All containers have requirements of their elements, e.g. Must have default constructor, must be assignable, etc. This is where I think your problem lies.

    0 讨论(0)
提交回复
热议问题