本文整理汇总了C++中QSharedMemory类的典型用法代码示例。如果您正苦于以下问题:C++ QSharedMemory类的具体用法?C++ QSharedMemory怎么用?C++ QSharedMemory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSharedMemory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: temporaryOutDataStream
QDataStream &operator<<(QDataStream &out, const ValuesChangedCommand &command)
{
static const bool dontUseSharedMemory = !qgetenv("DESIGNER_DONT_USE_SHARED_MEMORY").isEmpty();
if (!dontUseSharedMemory && command.valueChanges().count() > 5) {
static quint32 keyCounter = 0;
++keyCounter;
command.m_keyNumber = keyCounter;
QByteArray outDataStreamByteArray;
QDataStream temporaryOutDataStream(&outDataStreamByteArray, QIODevice::WriteOnly);
temporaryOutDataStream.setVersion(QDataStream::Qt_4_8);
temporaryOutDataStream << command.valueChanges();;
QSharedMemory *sharedMemory = createSharedMemory(keyCounter, outDataStreamByteArray.size());
if (sharedMemory) {
std::memcpy(sharedMemory->data(), outDataStreamByteArray.constData(), sharedMemory->size());
out << command.keyNumber();
return out;
}
}
out << qint32(0);
out << command.valueChanges();
return out;
}
示例2: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setOrganizationName(APP_ORG);
a.setApplicationVersion(APP_VERSION);
a.setApplicationName(APP_NAME);
QTranslator translator;
const QStringList localeDirs({QString("%1/languages").arg(QDir::currentPath()),
QString(qApp->applicationDirPath() + "/languages"),
QString("/usr/share/%1/languages").arg(APP_NAME),
QString("/usr/local/share/%1/languages").arg(APP_NAME),
QString(QDir::home().absolutePath() + "/.local/share/%1/languages").arg(APP_NAME),
QString(QDir::currentPath().left(QDir::currentPath().lastIndexOf("/")) + "/share/%1/languages").arg(APP_NAME)});
const QString langFile(qApp->applicationName());
foreach(const QString &dir, localeDirs){
if (translator.load(QLocale::system(),langFile, "_", dir )) {
qApp->installTranslator(&translator);
break;
}
}
QApplication::setQuitOnLastWindowClosed(false);
PopupWindow w;
w.hide();
QSharedMemory sharedMemory;
sharedMemory.setKey("QtAlsaVolume");
if (sharedMemory.attach()) {
return 0;
}
if (!sharedMemory.create(1)) {
return 0;
}
else{
return a.exec();
}
}
示例3: sipReleaseType
static PyObject *meth_QSharedMemory_setKey(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
const QString * a0;
int a0State = 0;
QSharedMemory *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QSharedMemory, &sipCpp, sipType_QString,&a0, &a0State))
{
Py_BEGIN_ALLOW_THREADS
sipCpp->setKey(*a0);
Py_END_ALLOW_THREADS
sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State);
Py_INCREF(Py_None);
return Py_None;
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QSharedMemory, sipName_setKey, NULL);
return NULL;
}
示例4: readonly_segfault
int readonly_segfault()
{
QSharedMemory sharedMemory;
sharedMemory.setKey("readonly_segfault");
sharedMemory.create(1024, QSharedMemory::ReadOnly);
sharedMemory.lock();
set(sharedMemory, 0, 'a');
sharedMemory.unlock();
return EXIT_SUCCESS;
}
示例5: 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;
}
}
示例6: i
/*!
Destructor
*/
TasDataShare::~TasDataShare()
{
QMutableHashIterator<QString, QSharedMemory*> i(mStoredDataBlocks);
while (i.hasNext()) {
i.next();
QSharedMemory* mem = i.value();
mem->detach();
delete mem;
}
mStoredDataBlocks.clear();
}
示例7: detachSharedData
bool TasDataShare::detachSharedData(const QString& identifier)
{
if(mStoredDataBlocks.contains(identifier)){
QSharedMemory* mem = mStoredDataBlocks.value(identifier);
if(!mem->detach()){
return false;
}
delete mem;
mem = 0;
mStoredDataBlocks.remove(identifier);
}
return true;
}
示例8: SingleApp
int SingleApp(){//TODO:problem.
int ret = 1;
QSharedMemory sharedMemory;
sharedMemory.setKey("FishProjectApp");
// if (sharedMemory.create(1) && sharedMemory.error() != QSharedMemory::AlreadyExists)
if(sharedMemory.attach())
{
qDebug()<<"single";
return 0;
}
sharedMemory.create(1);
qDebug()<<"create";
return ret;
}
示例9: QSharedMemory
void *COMPRESSOR_create_ladspa(const char *key){
QSharedMemory *shared = new QSharedMemory(key);
if(shared->attach()==false){
fprintf(stderr,"Ladspa compressor: Couldn't attach... Error: %s\n",shared->error()==QSharedMemory::NoError?"No error (?)":shared->errorString().toAscii().data());
exit(0);
}
mydsp *dsp = (mydsp*)shared->data();
fprintf(stderr,"dsp: %p.\n",dsp);
portData* port_data = new portData(dsp->mydsp::getNumInputs(), dsp->mydsp::getNumOutputs());
dsp->mydsp::buildUserInterface(port_data); // buildUserInterface is called twice on the dsp data. One time in each process.
return new PLUGIN(0, port_data, dsp);
}
示例10: main
int main(int argc, char *argv[])
{
qRegisterMetaTypeStreamOperators<SQProfile>("SQProfile");
QApplication a(argc, argv);
signal(SIGINT, onSIGINT_TERM);
signal(SIGTERM, onSIGINT_TERM);
a.setApplicationName(QString("shadowsocks-qt5"));
a.setApplicationDisplayName(QString("Shadowsocks-Qt5"));
a.setApplicationVersion(APP_VERSION);
#ifdef Q_OS_WIN
if (QLocale::system().country() == QLocale::China) {
a.setFont(QFont("Microsoft Yahei", 9, QFont::Normal, false));
}
else {
a.setFont(QFont("Segoe UI", 9, QFont::Normal, false));
}
QIcon::setThemeName("Breeze");
#endif
QTranslator ssqt5t;
ssqt5t.load(QLocale::system(), "ss-qt5", "_", ":/i18n");
a.installTranslator(&ssqt5t);
MainWindow w;
QSharedMemory sharedMem;
sharedMem.setKey("Shadowsocks-Qt5");
if (w.isOnlyOneInstance()) {
if (!sharedMem.create(1)) {
QMessageBox::critical(&w, QObject::tr("Error"), QObject::tr("Another instance of Shadowsocks-Qt5 is already running."));
return -1;
}
}
w.show();
if (w.isHideWindowOnStartup()) {
if (w.isUsingAppIndicator()) {
QTimer::singleShot(5, &w, SLOT(minimizeToSysTray()));
} else {
w.minimizeToSysTray();
}
}
return a.exec();
}
示例11: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("Scary HalloSoft");
QCoreApplication::setOrganizationDomain("hallosoft.de");
QCoreApplication::setApplicationName("Hallos Inspection Tool");
// Version
QString versionString = QString("%1.%2.%3.%4").arg(VERSION_MAJOR).arg(VERSION_MINOR).arg(VERSION_REVISION).arg(VERSION_BUILD);
a.setApplicationVersion(versionString);
qDebug() << "Version" << versionString;
// splash screen
QPixmap splashPixmap(":/pic/icons/Slpash.png");
Q_ASSERT(!splashPixmap.isNull());
QSharedMemory sharedMemory;
sharedMemory.setKey("HallosInspectionTool");
if (!sharedMemory.create(1))
{
qDebug() << "Shared memory:" << sharedMemory.errorString();
QMessageBox::warning(0,
QApplication::tr("Warning!"),
QApplication::tr("An instance of HIT is running!") );
exit(0); // Exit, a process is already running
}
QSplashScreen splash(splashPixmap);
splash.show();
qApp->processEvents();
splash.showMessage(QString("Version %1").arg(versionString), Qt::AlignBottom);
qApp->processEvents();
MainWindow w;
w.show();
splash.finish(&w);
return a.exec();
}
示例12: QSharedMemory
void *COMPRESSOR_create_shared(float sample_rate){
QString key = "radium_crashreporter_" + QString::number(QDateTime::currentMSecsSinceEpoch());
QSharedMemory *shared = new QSharedMemory(key);
if(shared->create(sizeof(Compressor_wrapper))==false){
fprintf(stderr,"COMPRESSOR_create_shared: Couldn't create... Error: %s\n",shared->error()==QSharedMemory::NoError?"No error (?)":shared->errorString().toAscii().data());
return NULL;
}
void *memory = shared->data();
Compressor_wrapper *wrapper = new(memory) Compressor_wrapper(sample_rate);
printf("memory: %p, shared: %p\n",memory,shared);
wrapper->key = key;
wrapper->shared = shared;
return wrapper;
}
示例13: sipConvertFromNewType
static PyObject *meth_QSharedMemory_key(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
QSharedMemory *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QSharedMemory, &sipCpp))
{
QString *sipRes;
Py_BEGIN_ALLOW_THREADS
sipRes = new QString(sipCpp->key());
Py_END_ALLOW_THREADS
return sipConvertFromNewType(sipRes,sipType_QString,NULL);
}
}
示例14: QSharedMemory
bool TasDataShare::storeSharedData(const QString& identifier, const TasSharedData& data, QString& errMsg)
{
QSharedMemory* storage = new QSharedMemory(identifier);
QByteArray array = data.asArray();
int size = array.size();
if(!storage->create(size)){
delete storage;
return false;
}
storage->lock();
char *to = (char*)storage->data();
const char *from = array.data();
memcpy(to, from, qMin(storage->size(), size));
storage->unlock();
mStoredDataBlocks.insert(identifier, storage);
errMsg = " key:" + storage->key();
return true;
}
示例15: json
// 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());
}