hsin.xu的个人主页

http://www.qtcn.org/bbs/u/188492  [收藏] [复制]

hsin.xu

  • 1

    关注

  • 2

    粉丝

  • 1

    访客

  • 等级:新手上路
  • 总积分:1
  • 保密,1990-10-10

最后登录:2019-08-24

更多资料

日志

进程间通信--共享内存b

2019-08-08 15:53
#include "dialog.h"#include "ui_dialog.h"#include <QBuffer>#include <QDataStream>#include <QImage>#include <QPixmap>
Dialog::Dialog(QWidget *parent) :    QDialog(parent),    ui(new Ui::Dialog){    ui->setupUi(this);    sharemem_.setKey("shareimg");}
Dialog::~Dialog(){    delete ui;}
void Dialog::on_pushButton_clicked(){    sharemem_.lock();
    if(!sharemem_.isAttached())    {        sharemem_.attach();    }
    int size=sharemem_.size();    QByteArray bytearr;    bytearr.resize(size);    char * to=bytearr.data();    char * from=(char *)sharemem_.data();    memcpy(to,from,size);    QDataStream stream(&bytearr,QIODevice::ReadOnly);    QImage image;    stream>>image;
    ui->label->setPixmap(QPixmap::fromImage(image).scaled(ui->label->width(),ui->label->height()));
    sharemem_.unlock();    sharemem_.detach();}
分类:默认分类|回复:0|浏览:92|全站可见|转载
 

下一篇:

上一篇: 进程间通信--共享内存a

Powered by phpwind v8.7 Certificate Copyright Time now is:08-25 12:41
©2005-2016 QTCN开发网 版权所有 Gzip disabled