本文整理汇总了C++中QSharedMemory::isAttached方法的典型用法代码示例。如果您正苦于以下问题:C++ QSharedMemory::isAttached方法的具体用法?C++ QSharedMemory::isAttached怎么用?C++ QSharedMemory::isAttached使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSharedMemory
的用法示例。
在下文中一共展示了QSharedMemory::isAttached方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openAida
void conflict_core::openAida(){
aida.setKey("AIDA64_SensorValues");
if (aida.isAttached()){
aida.detach();
}
if (!aida.create(10000)){
conflict.aidaOpen = false;
}else{
conflict.aidaOpen = true;
}
}
示例2: QSharedMemory
static QSharedMemory *createSharedMemory(qint32 key, int byteCount)
{
QSharedMemory *sharedMemory = new QSharedMemory(QString(valueKeyTemplateString).arg(key));
bool sharedMemoryIsCreated = sharedMemory->create(byteCount);
if (!sharedMemoryIsCreated) {
if (sharedMemory->isAttached())
sharedMemory->attach();
sharedMemory->detach();
sharedMemoryIsCreated = sharedMemory->create(byteCount);
}
if (sharedMemoryIsCreated) {
globalSharedMemoryCache.insert(key, sharedMemory);
return sharedMemory;
}
return 0;
}
示例3: isRunning
bool Application::isRunning()
{
bool running = BaseApplication::isRunning();
QSharedMemory *sharedMem = new QSharedMemory(id() + QLatin1String("-shared-memory-key"), this);
if (!running) {
// First instance creates shared memory and store PID
if (sharedMem->create(sizeof(DWORD)) && sharedMem->lock()) {
*(static_cast<DWORD*>(sharedMem->data())) = ::GetCurrentProcessId();
sharedMem->unlock();
}
}
else {
// Later instances attach to shared memory and retrieve PID
if (sharedMem->attach() && sharedMem->lock()) {
::AllowSetForegroundWindow(*(static_cast<DWORD*>(sharedMem->data())));
sharedMem->unlock();
}
}
if (!sharedMem->isAttached())
qWarning() << "Failed to initialize shared memory: " << sharedMem->errorString();
return running;
}
示例4: out
/** Constructor. Parses the command-line arguments, resets Rshare's
* configuration (if requested), and sets up the GUI style and language
* translation. */
Rshare::Rshare(QStringList args, int &argc, char **argv, const QString &dir)
: QApplication(argc, argv)
{
mStartupTime = QDateTime::currentDateTime();
localServer = NULL;
//Initialize connection to LocalServer to know if other process runs.
{
QString serverName = QString(TARGET);
if (!args.isEmpty()) {
// load into shared memory
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
QDataStream out(&buffer);
out << args;
int size = buffer.size();
QSharedMemory newArgs;
newArgs.setKey(serverName + "_newArgs");
if (newArgs.isAttached()) newArgs.detach();
if (!newArgs.create(size)) {
std::cerr << "(EE) Rshare::Rshare Unable to create shared memory segment of size:"
<< size << " error:" << newArgs.errorString().toStdString() << "." << std::endl;
#ifdef Q_OS_UNIX
std::cerr << "Look with `ipcs -m` for nattch==0 segment. And remove it with `ipcrm -m 'shmid'`." << std::endl;
//No need for windows, as it removes shared segment directly even when crash.
#endif
newArgs.detach();
::exit(EXIT_FAILURE);
}
newArgs.lock();
char *to = (char*)newArgs.data();
const char *from = buffer.data().data();
memcpy(to, from, qMin(newArgs.size(), size));
newArgs.unlock();
// Connect to the Local Server of the main process to notify it
// that a new process had been started
QLocalSocket localSocket;
localSocket.connectToServer(QString(TARGET));
std::cerr << "Rshare::Rshare waitForConnected to other instance." << std::endl;
if( localSocket.waitForConnected(100) )
{
std::cerr << "Rshare::Rshare Connection etablished. Waiting for disconnection." << std::endl;
localSocket.waitForDisconnected(1000);
newArgs.detach();
std::cerr << "Rshare::Rshare Arguments was sended." << std::endl
<< " To disable it, in Options - General - Misc," << std::endl
<< " uncheck \"Use Local Server to get new Arguments\"." << std::endl;
::exit(EXIT_SUCCESS); // Terminate the program using STDLib's exit function
}
newArgs.detach();
}
// No main process exists
// Or started without arguments
// So we start a Local Server to listen for connections from new process
localServer= new QLocalServer();
QObject::connect(localServer, SIGNAL(newConnection()), this, SLOT(slotConnectionEstablished()));
updateLocalServer();
}
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
qInstallMessageHandler(qt_msg_handler);
#else
qInstallMsgHandler(qt_msg_handler);
#endif
#ifndef __APPLE__
/* set default window icon */
setWindowIcon(QIcon(":/icons/logo_128.png"));
#endif
mBlink = true;
QTimer *timer = new QTimer(this);
timer->setInterval(500);
connect(timer, SIGNAL(timeout()), this, SLOT(blinkTimer()));
timer->start();
timer = new QTimer(this);
timer->setInterval(60000);
connect(timer, SIGNAL(timeout()), this, SIGNAL(minuteTick()));
timer->start();
/* Read in all our command-line arguments. */
parseArguments(args);
/* Check if we're supposed to reset our config before proceeding. */
if (_args.contains(ARG_RESET)) {
Settings->reset();
}
/* Handle the -loglevel and -logfile options. */
//.........这里部分代码省略.........