hsin.xu的个人主页

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

hsin.xu

  • 1

    关注

  • 2

    粉丝

  • 1

    访客

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

最后登录:2019-08-24

更多资料

日志

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

2019-08-08 15:52
#include "dialog.h"#include "ui_dialog.h"#include <QFileDialog>#include <QImage>#include <QPixmap>#include <QBuffer>#include <QDataStream>
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(){    QString str=QFileDialog::getOpenFileName(this,"open image","D:\\","bmp (*.*)");    if(!str.isEmpty())    {        QImage img;        if(img.load(str))        {            ui->label->setPixmap(QPixmap::fromImage(img).scaled(ui->label->width(),ui->label->height()));
            QBuffer buffer;            buffer.open(QBuffer::ReadWrite);            QDataStream stream(&buffer);            stream<<img;
            int size=buffer.size();            if(sharemem_.isAttached())            {                sharemem_.detach();            }            if(sharemem_.create(size))            {                sharemem_.lock();
                char * to=(char *)sharemem_.data();                const char * from=buffer.data().data();                memcpy(to,from,qMin(sharemem_.size(),size));
                sharemem_.unlock();            }        }    }}
分类:默认分类|回复:0|浏览:79|全站可见|转载
 

下一篇: 进程间通信--共享内存b

上一篇:

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