本文整理汇总了C++中QSharedMemory::constData方法的典型用法代码示例。如果您正苦于以下问题:C++ QSharedMemory::constData方法的具体用法?C++ QSharedMemory::constData怎么用?C++ QSharedMemory::constData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSharedMemory
的用法示例。
在下文中一共展示了QSharedMemory::constData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotConnectionEstablished
/**
* @brief Executed when new instance connect command is sent to LocalServer
*/
void Rshare::slotConnectionEstablished()
{
QLocalSocket *socket = localServer->nextPendingConnection();
socket->close();
delete socket;
QSharedMemory newArgs;
newArgs.setKey(QString(TARGET) + "_newArgs");
if (!newArgs.attach())
{
std::cerr << "(EE) Rshare::slotConnectionEstablished() Unable to attach to shared memory segment."
<< newArgs.errorString().toStdString() << std::endl;
return;
}
QBuffer buffer;
QDataStream in(&buffer);
QStringList args;
newArgs.lock();
buffer.setData((char*)newArgs.constData(), newArgs.size());
buffer.open(QBuffer::ReadOnly);
in >> args;
newArgs.unlock();
newArgs.detach();
emit newArgsReceived(args);
while (!args.empty())
{
std::cerr << "Rshare::slotConnectionEstablished args:" << QString(args.takeFirst()).toStdString() << std::endl;
}
}
示例2: updateAida
void conflict_core::updateAida(){
QBuffer buffer;
QDataStream in(&buffer);
QString text;
if(conflict.aidaOpen){
aida.lock();
buffer.setData((char*)aida.constData(), aida.size());
buffer.open(QBuffer::ReadOnly);
in >> text;
ui->debugOutputOut->append(text);
aida.unlock();
}
示例3: in
// Example how to get json using shared memory. Not tested :-D
std::pair<bool, QString> json() {
QSharedMemory sharedMemory;
if (!sharedMemory.attach()) {
return std::make_pair<bool, QString>(false, QString());
}
QBuffer buffer;
QDataStream in(&buffer);
QString json;
sharedMemory.lock();
buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
buffer.open(QBuffer::ReadOnly);
in >> json;
sharedMemory.unlock();
sharedMemory.detach();
return std::make_pair<bool, QString>(false, QString());
}
示例4: isRunning
// Check if the application is running. Optionally write something to its shared memory.
static bool isRunning(const char* command){
// Try to create shared memory (if successful, application was not already running)
if(!appShare.create(SHMEM_SIZE) || !appShare.lock()){
// Lock existing shared memory
if(!appShare.attach() || !appShare.lock())
return true;
bool running = false;
if(appShare.size() == SHMEM_SIZE_V015){
// Old shmem - no PID listed so assume the process is running, and print the command directly to the buffer
if(command){
void* data = appShare.data();
snprintf((char*)data, SHMEM_SIZE_V015, "%s", command);
}
running = true;
} else {
// New shmem. Scan the contents of the shared memory for a PID
QStringList lines = QString((const char*)appShare.constData()).split("\n");
if(pidActive(lines)){
running = true;
// Append the command
if(command){
lines.append(QString("Option ") + command);
QByteArray newMem = lines.join("\n").left(SHMEM_SIZE).toLatin1();
// Copy the NUL byte as well as the string
memcpy(appShare.data(), newMem.constData(), newMem.length() + 1);
}
}
}
if(running){
appShare.unlock();
return true;
}
}
// Not already running. Initialize the shared memory with our PID
snprintf((char*)appShare.data(), appShare.size(), "PID %ld", (long)getpid());
appShare.unlock();
return false;
}
示例5:
char* address_jt9_() {return (char*)mem_jt9.constData();}