进程通信QSharedMemory


写播放器的时候 添加功能多启动 后 首次启动的  最大化


..

class ShareMem
{

public:
	QSharedMemory*share;
	char data;
	
	~ShareMem()
	{
		share->detach();
		delete share;
	}
	ShareMem()
	{

		share=new QSharedMemory("shareMem");
	
		data = 2;
		cout << " create shareMem status :  "<<share->create(1, QSharedMemory::ReadWrite) << endl;;

		share->lock();


		memcpy((char*)share->data(), &data, 1));

		share->unlock();

		//share->detach();
		//delete share;

	}

	bool isNotify()
	{


		QSharedMemory share;
		share.setKey("shareMem");
		share.attach();
		share.lock();

		memcpy(&data,share.data() , 1);


		share.unlock();
		share.detach();

		if (data== 2)return false;
		
	

		share.attach();
		share.lock();

		data = 2;
		memcpy((char*)share.data(), &data, 1);
		share.unlock();
		share.detach();


		return true;

	}


...........



};


你可能感兴趣的:(进程通信QSharedMemory)