QSHaredMemory在Windows中的行为不一致
QSharedMemory inconsistent behaviour in Windows
我正在玩QSharedMemory
,我不确定我只是发现一个严重的错误还是我做错了什么。情况是,文档说如果没有相同键的内存,QSharedMemory::create()
应该返回true,否则应返回false,并且应检查QSharedMemory::error()
以查看发生的事情。
我当前的代码是:
QSharedMemory sm("smtest");
sm.setKey("smtest"); // <--- not needed as I already set the key in the initializator, but I'm leaving it anyways, just for the test
qDebug() << sm.create(1);
qDebug() << sm.create(1); //<--- I expect this to return false, but it returns true.
qDebug() << sm.error(); //<--. I expect this to return QSharedMemory::AlreadyExists, but QSharedMemory::NoError is returned instead.
//wtf?!
我的问题是:我刚刚在QT4中找到了一个非常大的错误还是我做错了什么?
ps:此代码在Windows 7 x64
上运行编辑:为了清楚起见,如果我两次运行该代码,第二个应用程序应检测到第一个应用程序,但不是。
编辑2:我在这里报告了一个错误
这绝对是一个错误,请阅读我的错误报告https://bugreports.qt.io/browse/qtbug-27765
我最近安装了一个补丁以解决此问题。如果您想解决这个问题,则需要投票。
我只是在linux上运行:
#include <QCoreApplication>
#include <QSharedMemory>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSharedMemory sm("smtest");
sm.setKey("smtest"); // <--- not needed as I already set the key in the initializator, but I'm leaving it anyways, just for the test
qDebug() << sm.create(1);
qDebug() << sm.create(1); //<--- I expect this to return false, but it returns true.
qDebug() << sm.error(); //<--. I expect this to return QSharedMemory::AlreadyExists, but QSharedMemory::NoError is returned instead.
//wtf?!
return 0;
}
第一次运行
true
false
4
可能是您没有创建QCoreApplication?许多QT的东西往往取决于所创建的东西。
编辑:要强调,上面仅在第一次运行中发生。随后的运行始终给出false-false。
edit2:在Windows上,结果对我来说也是真实的。
edit3:似乎是一个错误,听起来很像:https://bugreports.qt.io/browse/qtbug-5123
相关文章:
- 大于65535的C++数组[size]引发不一致的溢出
- 在 C++(和 C)中进行类型转换时明显不一致
- 填充上编译器生成的复制构造函数之间的不一致
- 犰狳的 print() 方法和 cout 在从 Rcpp 调用时顺序不一致
- CreateDIBSection为同一图像返回不一致的位图位值
- 在 Qml 中从 QSqlTableModel 中删除单行时视图不一致
- 模板参数推导不一致
- 声明中不一致的no是否违反ODR?
- 如何删除分支因子不一致的树,最大为 30,40
- 从 C++ 函数与 Python 函数返回的不一致值用于偏斜正态分布
- 从 C 字符串构造 std::string 与从另一个 std::string 构造 std::string 不一致
- 这种比较是否不一致(或者存在其他问题)?
- 以下可变参数模板行为是否不一致?
- 如何修复我的链表读数不一致的问题?
- 在C++17中,为什么类模板和函数模板的指针类型推导明显不一致
- void 函数中的指针参数返回不一致的值
- 如何查找导致结果不一致的代码
- 为什么Qt资源被加载到Linux而不是Windows中?
- QSHaredMemory在Windows中的行为不一致
- Windows睡眠不一致