基于QtQuick二维码解码

"Qt for QR Decode"

Posted by Tobyyi on February 18, 2017

“Yeah It’s on. ”

二维码解码模块

二维码解码模块是基于C++组织,依赖开源的QZXing编码项目qrdecode 目前已经将其组织成能在QtQuick上面使用的QML扩展的插件形式,你 可以使用如下代码进行编码: 预览 Add Logo

No Logo

import QtQuick 2.3
import duoduo.decode.components 1.0
DDQRDecoder{
    id:decode
    enabledDecoders: DDQRDecoder.DecoderFormat_QR_CODE
    onDecodingStarted: {
        console.log("扫描开始 ");
        title.text = "扫描中...";
    }
    onDecodingFinished: {
        console.log("扫描结果-----: "+succeeded);
    }
    onTagFound: {
        console.log("扫描结束:"+tag);
        title.text = tag;
    }
    onDecodeimageerror:{
        console.log("图片损坏:"+error);
    }
}

总结

应用

该插件需要Qt5.x版本或者更高版本进行编

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import duoduo.encode.components 1.0
import duoduo.decode.components 1.0
ApplicationWindow {
    title: qsTr("WelCome To QtQuick")
    width: 228
    height: 428
    visible: true
    flags: Qt.FramelessWindowHint
    Text {
        id: title
        text: qsTr("WelCome To QtQuick")
        width: parent.width
        height: 30
        anchors.top: parent.top
        anchors.topMargin: 10
        font.pixelSize: 16
        font.family: "Comic Sans MS"
        horizontalAlignment: Text.AlignHCenter
        color: ww.qrForeground
    }
    //编码
    QREnCode{
        id:ww
        width: 128
        height: 128
        qrData: "QQGroup:312125701"
        qrForeground: "#00c853"
        qrLogo: "logo256.png"
        anchors.centerIn: parent
    }
    //解码
    DDQRDecoder{
        id:decode
        enabledDecoders: DDQRDecoder.DecoderFormat_QR_CODE
        onDecodingStarted: {
            console.log("扫描开始 ");
            title.text = "扫描中...";
        }
        onDecodingFinished: {
            console.log("扫描结果-----: "+succeeded);
        }
        onTagFound: {
            console.log("扫描结束:"+tag);
            title.text = tag;
        }
        onDecodeimageerror:{
            console.log("图片损坏:"+error);
        }
    }
    MainForm {
        anchors.bottom: parent.bottom
        width: parent.width
        height: 30
        button1.onClicked: {
            decode.decodeImageQML(ww)
        }
        button2.onClicked: {
            decode.decodeImageFromFile("xxxxx/20151607182842.png");
        }
    }
}

实现 QML Extension USE C++ (QQmlExtensionPlugin)

Implemented a QML Extension module that:

属性

  • processingTime (decode elapsed time)
  • enabledDecoders (set decode mode)

信号

  • void decodingStarted();
  • void decodingFinished(bool succeeded);
  • void tagFound(QString tag);
  • void enabledFormatsChanged();
  • void decodeimageerror(bool error);

槽和方法

  • decodeImage(QImage image, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation = false) (decode image object )
  • decodeImageFromFile(QString imageFilePath, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation = false) (decode local image or resource file)
  • decodeImageQML(QObject *item) (The decoding function accessible from QML)
  • decodeSubImageQML(QObject* item,const double offsetX = 0 , const double offsetY = 0,const double width = 0, const double height = 0) (Able to set the decoding * of a portion of the image.)
  • getProcessTimeOfLastDecoding() (get elapsed time)

参考

https://github.com/SonyPony/QZXing