here is my code:
QSharedMemory numofallplayers;
void sesman::run()
{
numofallplayers.setKey("numofallplayers");
numofallplayers.create(sizeof(qint64), QSharedMemory::ReadWrite);
qDebug
() <<
"session manager thread starts from" <<
QThread::currentThread();
qDebug() << "seting total players to zero";
sesman::SetNumOfAllPlayers(0);
qDebug() << "num of players total: " << sesman::GetNumOfAllPlayers(); //just to check
.
.
.
cleanup();
}
void sesman::SetNumOfAllPlayers(qint64 totalplayers)
{
if(numofallplayers.isAttached()){
numofallplayers.detach();
}
if(!numofallplayers.attach(QSharedMemory::ReadWrite)){
//some error
qDebug() << "attach numofallplayers failed" << numofallplayers.errorString();
}
numofallplayers.lock();
qint64* totalpl = (qint64*)numofallplayers.data();
*totalpl = totalplayers;
numofallplayers.unlock();
if(!numofallplayers.detach())
qDebug() << "unable to detach";
}
QSharedMemory numofallplayers;
void sesman::run()
{
numofallplayers.setKey("numofallplayers");
numofallplayers.create(sizeof(qint64), QSharedMemory::ReadWrite);
qDebug() << "session manager thread starts from" << QThread::currentThread();
qDebug() << "seting total players to zero";
sesman::SetNumOfAllPlayers(0);
qDebug() << "num of players total: " << sesman::GetNumOfAllPlayers(); //just to check
.
.
.
cleanup();
}
void sesman::SetNumOfAllPlayers(qint64 totalplayers)
{
if(numofallplayers.isAttached()){
numofallplayers.detach();
}
if(!numofallplayers.attach(QSharedMemory::ReadWrite)){
//some error
qDebug() << "attach numofallplayers failed" << numofallplayers.errorString();
}
numofallplayers.lock();
qint64* totalpl = (qint64*)numofallplayers.data();
*totalpl = totalplayers;
numofallplayers.unlock();
if(!numofallplayers.detach())
qDebug() << "unable to detach";
}
To copy to clipboard, switch view to plain text mode
and i get following error
seting total players to zero
attach numofallplayers failed "QSharedMemory::handle:: UNIX key file doesn't exist"
The program has unexpectedly finished.
Can someone help? what is wrong with my code?
thanks a lot for any help...
Bookmarks