本文整理汇总了C++中QSharedMemory::error方法的典型用法代码示例。如果您正苦于以下问题:C++ QSharedMemory::error方法的具体用法?C++ QSharedMemory::error怎么用?C++ QSharedMemory::error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSharedMemory
的用法示例。
在下文中一共展示了QSharedMemory::error方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QSharedMemory
static mydsp *create_shared_dsp(){
QString key = "radium_crashreporter_" + QString::number(QDateTime::currentMSecsSinceEpoch());
QSharedMemory *shared = new QSharedMemory(key);
if(shared->create(sizeof(mydsp))==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();
mydsp *dsp = new(memory) mydsp();
#if 0
printf("memory: %p, shared: %p\n",memory,shared);
dsp->key = key;
dsp->shared = shared;
#endif
//printf("system: %d\n",system(QString(QString("xterm -e gdb /home/kjetil/radium_compressor/radium_compressor --args --ladspa-slave ")+key).toAscii()));
printf("system: %d\n",system(QString(QString("xterm -e gdb --args /home/kjetil/radium_compressor/radium_compressor --ladspa-slave ")+key+" &").toAscii()));
return dsp;
#if 0
if(fork()!=0){
return dsp;
}else{
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);
}
char *argv[1]={(char*)"radium_compressor"};
mydsp *dsp = (mydsp*)shared->data();
fprintf(stderr,"dsp: %p.\n",dsp);
portData* port_data = new portData(dsp->getNumInputs(), dsp->getNumOutputs());
dsp->buildUserInterface(port_data); // This is the second time buildUserInterface is called twice on the dsp data. One time in each process.
start_program(1,argv,new PLUGIN(0, port_data, dsp));
exit(0);
return NULL;
}
#endif
}
示例2: PLUGIN
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);
}
示例3: 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;
}
示例4: producer
int producer()
{
QSharedMemory producer;
producer.setKey("market");
int size = 1024;
if (!producer.create(size)) {
if (producer.error() == QSharedMemory::AlreadyExists) {
if (!producer.attach()) {
qWarning() << "Could not attach to" << producer.key();
return EXIT_FAILURE;
}
} else {
qWarning() << "Could not create" << producer.key();
return EXIT_FAILURE;
}
}
// tell parent we're ready
//qDebug("producer created and attached");
puts("");
fflush(stdout);
if (!producer.lock()) {
qWarning() << "Could not lock" << producer.key();
return EXIT_FAILURE;
}
set(producer, 0, 'Q');
if (!producer.unlock()) {
qWarning() << "Could not lock" << producer.key();
return EXIT_FAILURE;
}
int i = 0;
while (i < 5) {
if (!producer.lock()) {
qWarning() << "Could not lock" << producer.key();
return EXIT_FAILURE;
}
if (get(producer, 0) == 'Q') {
if (!producer.unlock()) {
qWarning() << "Could not unlock" << producer.key();
return EXIT_FAILURE;
}
QTest::qSleep(1);
continue;
}
//qDebug() << "producer:" << i);
++i;
set(producer, 0, 'Q');
if (!producer.unlock()) {
qWarning() << "Could not unlock" << producer.key();
return EXIT_FAILURE;
}
QTest::qSleep(1);
}
if (!producer.lock()) {
qWarning() << "Could not lock" << producer.key();
return EXIT_FAILURE;
}
set(producer, 0, 'E');
if (!producer.unlock()) {
qWarning() << "Could not unlock" << producer.key();
return EXIT_FAILURE;
}
//qDebug("producer done");
// Sleep for a bit to let all consumers exit
getchar();
return EXIT_SUCCESS;
}