zoukankan      html  css  js  c++  java
  • qt生成二维码

    到官网下载qrencode

    http://fukuchi.org/works/qrencode/index.html.en
    qrenc.c不用,这个是测试用的,把config.h.in文件改为config.h文件,把.h文件和.cpp文件导入,在整个项目的pro文件中加入
    DEFINES +=HAVE_CONFIG_H
    OTHER_FILES += qrcode/config.h.in
    #include "qrcode/qrencode.h"
    void MainWindow::GenerateQRcode(QString tempstr)
    {
        QRcode *qrcode;
        qrcode=QRcode_encodeString(tempstr.toStdString().c_str(),2,QR_ECLEVEL_Q,QR_MODE_8,1);
        qint32 temp_width=ui->label->width();
        qint32 temp_height=ui->label->height();
        qDebug()<<"temp_width="<<temp_width<<";temp_height="<<temp_height;
        qint32 qrcode_width=qrcode->width>0?qrcode->1;
        double scale_x=(double)temp_width/(double)qrcode_width;
        double scale_y=(double)temp_height/(double)qrcode_width;
        QImage mainimg=QImage(temp_width,temp_height,QImage::Format_ARGB32);
        QPainter painter(&mainimg);
        QColor background(Qt::white);
        painter.setBrush(background);
        painter.setPen(Qt::NoPen);
        painter.drawRect(0,0,temp_width,temp_height);
        QColor foreground(Qt::black);
        painter.setBrush(foreground);
        for(qint32 y=0;y<qrcode_width;y++)
        {
            for(qint32 x=0;x<qrcode_width;x++)
            {
                unsigned char b=qrcode->data[y*qrcode_width+x];
                if(b &0x01)
                {
                    QRectF r(x*scale_x,y*scale_y,scale_x,scale_y);
                    painter.drawRects(&r,1);
                }
            }
        }
    
       QPixmap mainmap=QPixmap::fromImage(mainimg);
    
       QLabel *plabel = new QLabel();
    
       plabel->setPixmap(mainmap);
       plabel->setVisible(true);
    }
  • 相关阅读:
    使用xtrabackup对MySQL进行备份和恢复
    魔棒工具RegionGrow算法简介
    编程之美扫雷篇
    从繁体字到书法
    谈读书如何才能提升你的工作能力
    魔兽争霸拼图照片一张
    做你心目中的达文西
    六一儿童节的礼物那些游戏中你不知道的玩法
    DIY手工制作Rhombicuboctahedron
    ul样式与jquery1.4.1冲突
  • 原文地址:https://www.cnblogs.com/xupeidong/p/9815668.html
Copyright © 2011-2022 走看看