当前位置: 首页>>代码示例>>C++>>正文


C++ QSharedMemory类代码示例

本文整理汇总了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;
}
开发者ID:MECTsrl,项目名称:imx_mect,代码行数:28,代码来源:valueschangedcommand.cpp

示例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();
    }
}
开发者ID:Vitozz,项目名称:kukuruzo,代码行数:35,代码来源:main.cpp

示例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;
}
开发者ID:ClydeMojura,项目名称:android-python27,代码行数:26,代码来源:sipQtCoreQSharedMemory.cpp

示例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;
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:10,代码来源:main.cpp

示例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;
	}
}
开发者ID:jiangxilong,项目名称:RetroShare,代码行数:36,代码来源:rshare.cpp

示例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();
}
开发者ID:jppiiroinen,项目名称:cutedriver-agent_qt,代码行数:14,代码来源:tasdatashare.cpp

示例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;
}
开发者ID:jppiiroinen,项目名称:cutedriver-agent_qt,代码行数:13,代码来源:tasdatashare.cpp

示例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;
}
开发者ID:enaldick,项目名称:QtProject_Fish,代码行数:14,代码来源:main.cpp

示例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);
}
开发者ID:kmatheussen,项目名称:radium_compressor,代码行数:16,代码来源:myladspa.cpp

示例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();
}
开发者ID:iGeekor,项目名称:shadowsocks-qt5,代码行数:47,代码来源:main.cpp

示例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();
}
开发者ID:HalloSoft,项目名称:Hit,代码行数:46,代码来源:main.cpp

示例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;
}
开发者ID:dieface,项目名称:radium-1,代码行数:17,代码来源:system_compressor_wrapper.cpp

示例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);
        }
    }
开发者ID:ClydeMojura,项目名称:android-python27,代码行数:18,代码来源:sipQtCoreQSharedMemory.cpp

示例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;
}
开发者ID:jppiiroinen,项目名称:cutedriver-agent_qt,代码行数:19,代码来源:tasdatashare.cpp

示例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());
}
开发者ID:bvgastel,项目名称:xmas,代码行数:22,代码来源:main.cpp


注:本文中的QSharedMemory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。