无法访问在'QReadWriteLock'Error 1错误C2248:'QReadWriteLock :: QReadWriteLock' [英] Cannot access private member declared in class 'QReadWriteLock'Error 1 error C2248: 'QReadWriteLock::QReadWriteLock'

查看:726
本文介绍了无法访问在'QReadWriteLock'Error 1错误C2248:'QReadWriteLock :: QReadWriteLock'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真的觉得像Qt中的一个错误。任何人有解决方案或应该将其作为一个错误?

This really feels like a bug in Qt. Anyone has a solution or should I file it as a bug?

#include <QReadWriteLock>

class FileInfoWrapper {

public:
    explicit FileInfoWrapper(const QFileInfo& _fileInfo);
    ~FileInfoWrapper();

private: // also tried public
    mutable QReadWriteLock lock_;

在使用它之前,我得到错误:

Before even using it, I get the error:


错误1错误C2248:'QReadWriteLock :: QReadWriteLock':无法访问在'QReadWriteLock'类中声明的私有成员

Error 1 error C2248: 'QReadWriteLock::QReadWriteLock' : cannot access private member declared in class 'QReadWriteLock'

如果它是私人/公共或我包括什么类无关紧要。我似乎无法在堆栈上创建它。相反,我使用'new'在堆上创建一个,但是当我尝试在构造函数中删除它时,我的应用程序崩溃:

Doesn't matter if it's private/public or what classes I include. I don't seem to be able to create it on the stack. Instead I created one on the heap using 'new', but when I try to delete it in the constructor my application crashes with:


未处理在MyApp.exe中的0x5090f39a(QtCored4.dll)异常:0xC0000005:访问冲突读取位置0xfeeeff0e。

Unhandled exception at 0x5090f39a (QtCored4.dll) in MyApp.exe: 0xC0000005: Access violation reading location 0xfeeeff0e.

调用堆栈:


QtCored4.dll!QHash ::〜QHash()行283 + 0xa字节C ++
QtCored4.dll!QReadWriteLockPrivate ::〜QReadWriteLockPrivate )+ 0x38字节C ++
QtCored4.dll!QReadWriteLockPrivate ::`标量删除析构函数'()+ 0xf字节C ++
QtCored4.dll!QReadWriteLock ::〜QReadWriteLock()行137 + 0x1e字节C ++
CloudSync.exe!FileInfoWrapper ::〜FileInfoWrapper()Line 76 + 0x15字节C ++

QtCored4.dll!QHash::~QHash() Line 283 + 0xa bytes C++ QtCored4.dll!QReadWriteLockPrivate::~QReadWriteLockPrivate() + 0x38 bytes C++ QtCored4.dll!QReadWriteLockPrivate::`scalar deleting destructor'() + 0xf bytes C++ QtCored4.dll!QReadWriteLock::~QReadWriteLock() Line 137 + 0x1e bytes C++ CloudSync.exe!FileInfoWrapper::~FileInfoWrapper() Line 76 + 0x15 bytes C++

QReadWriteLockPrivate中的变量'd'被删除两次。然而,这在另一个类中工作,我还必须在堆上创建锁,然后在构造函数中删除它。

The variable 'd' in QReadWriteLockPrivate seems to be deleted twice. However, this works in another class where I also had to create the lock on the heap and then delete it in the constructor.

在Visual Studio中运行Qt 4.8.0。有同样的问题在Qt的创建者4.7.4。

Running Qt 4.8.0 in Visual Studio. Had the same issue in Qt creator 4.7.4.

推荐答案

您必须使用指针,因为 QReadWriteLock 它使用 Q_DISABLE_COPY ),并以某种方式复制您的 FileInfoWrapper 对象(例如通过将其存储在容器中) br />
因此,指针地址在这些副本之间共享,并且每次复制都被删除一次。

You have to use a pointer because QReadWriteLock is not copyable (it uses Q_DISABLE_COPY) and you are somehow copying your FileInfoWrapper objects (by storing them in a container for example).
So the pointer address is shared between those copies, and deleted once for each copy.

QSharedPointer<QReadWriteLock> lock_;

这篇关于无法访问在'QReadWriteLock'Error 1错误C2248:'QReadWriteLock :: QReadWriteLock'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆