码迷,mamicode.com
首页 > 系统相关 > 详细

进程通信QSharedMemory

时间:2015-08-08 23:07:55      阅读:394      评论:0      收藏:0      [点我收藏+]

标签:






..

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;

	}






};


进程通信QSharedMemory

标签:

原文地址:http://my.oschina.net/kkkkkkkkkkkkk/blog/489596

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!