File: ZXingQtReader.cpp

package info (click to toggle)
zxing-cpp 3.0.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,204 kB
  • sloc: ansic: 69,384; cpp: 34,624; php: 2,790; python: 199; makefile: 31; sh: 3
file content (67 lines) | stat: -rw-r--r-- 1,549 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright 2020 Axel Waggershauser
*/
// SPDX-License-Identifier: Apache-2.0

#include "ZXingQt.h"

#include <QDebug>

using namespace ZXingQt;

void printBarcodes(const QList<Barcode>& barcodes)
{
	for (const auto& barcode : barcodes) {
		qDebug() << "Text:   " << barcode.text();
		qDebug() << "Format: " << barcode.format();
		qDebug() << "Content:" << barcode.contentType();
		qDebug() << "";
	}
}

int main(int argc, char* argv[])
{
	if (argc != 2) {
		qDebug().noquote() << "ZXingQtReader" << Version();
		qDebug() << "Usage:" << argv[0] << "<image file>";
		return 1;
	}

	QString filePath = QString::fromUtf8(argv[1]);

	QImage image = QImage(filePath);

	if (image.isNull()) {
		qDebug() << "Could not load the filename as an image:" << filePath;
		return 1;
	}

#if 0 // simple free function use case
	auto options = ReaderOptions()
					 .setFormats(ZXing::BarcodeFormat::AllReadable)
					 .setTryInvert(false)
					 .setTextMode(ZXing::TextMode::HRI)
					 .setMaxNumberOfSymbols(10);

	auto barcodes = ReadBarcodes(image, options);

	printBarcodes(barcodes);

	return barcodes.isEmpty() ? 1 : 0;
#else // QObject with signal/slot use case
	BarcodeReader reader;
	reader.setFormats({BarcodeFormat::AllReadable});
	reader.setTryInvert(false);
	reader.setTextMode(TextMode::HRI);
	QObject::connect(&reader, &BarcodeReader::foundBarcodes, &printBarcodes);
	QObject::connect(&reader, &BarcodeReader::foundNoBarcodes, []() {
		qDebug() << "No barcodes found";
	});

	reader.read(image);

	return 0;
#endif
}

#include "moc_ZXingQt.cpp"