..
class ShareMem { public: QSharedMemory*share; MainWindow*p; //char data; ShareMem(MainWindow *pp) { p = pp; QBuffer buffer; share=new QSharedMemory("shareMem"); buffer.setData("123");/*3 byte*/ cout << " create shareMem status : "<<share->create(buffer.size(), QSharedMemory::ReadWrite) << endl;; share->lock(); int size = buffer.size(); memcpy((char*)share->data(), buffer.data().data(), qMin(size, share->size())); share->unlock(); //share->detach(); } bool isNotify() { QBuffer buffer; QSharedMemory share; share.setKey("shareMem"); share.attach(); share.lock(); buffer.setData((char*)share.data(), share.size()); share.unlock(); share.detach(); QString s = (char*)buffer.data().data(); if (s == "123")return false; buffer.setData("123");/*3 byte*/ share.attach(); share.lock(); int size = buffer.size(); memcpy((char*)share.data(), buffer.data().data(), qMin(size, share.size())); share.unlock(); share.detach(); return true; } };
时间: 2024-11-06 12:42:13