How to use QZXing with cmake Qt 6.4
-
Hi,
I'm trying to use QZXing's encode and decode functions in my project. How does this work with cmake with Qt 6.4.0?
The latest thing I've tried is:
-
Adding the qzxing directory to my project then adding the following to my base project's CMakeLists.txt
SET(QZXING_USE_ENCODER ON) SET(ENABLE_ENCODER_GENERIC ON) SET(ENABLE_ENCODER_QR_CODE ON) add_subdirectory(./qzxing/src)Then, in one of my project files I
#include "./qzxing/src/QZXing.h"and try to use QZXing's example in their repo:QString data = "text to be encoded"; QImage barcode = QZXing::encodeData(data, QZXing::EncoderFormat_QR_CODE, QSize(width.toInt(), height.toInt()), QZXing::EncodeErrorCorrectionLevel_H);I don't get any errors after adding the above, but when I try to build, I get the following error:
:-1: error: error: undefined symbol: QZXing::encodeData(QString const&,QZXing::EncoderFormat, QSize,QZXing::EncodeErrorCorrectionLevel, bool, bool)I'm assuming that the above error is because the
.cppfiles aren't included with the project, so no function definitions. I haven't been able to find the correct cmake commands to do this, though (if that is the issue here).
-
-
Hi,
I'm trying to use QZXing's encode and decode functions in my project. How does this work with cmake with Qt 6.4.0?
The latest thing I've tried is:
-
Adding the qzxing directory to my project then adding the following to my base project's CMakeLists.txt
SET(QZXING_USE_ENCODER ON) SET(ENABLE_ENCODER_GENERIC ON) SET(ENABLE_ENCODER_QR_CODE ON) add_subdirectory(./qzxing/src)Then, in one of my project files I
#include "./qzxing/src/QZXing.h"and try to use QZXing's example in their repo:QString data = "text to be encoded"; QImage barcode = QZXing::encodeData(data, QZXing::EncoderFormat_QR_CODE, QSize(width.toInt(), height.toInt()), QZXing::EncodeErrorCorrectionLevel_H);I don't get any errors after adding the above, but when I try to build, I get the following error:
:-1: error: error: undefined symbol: QZXing::encodeData(QString const&,QZXing::EncoderFormat, QSize,QZXing::EncodeErrorCorrectionLevel, bool, bool)I'm assuming that the above error is because the
.cppfiles aren't included with the project, so no function definitions. I haven't been able to find the correct cmake commands to do this, though (if that is the issue here).
-
-
I appreciate the response @jsulm.
Does building as a library in Qt mean opening the
QZXing.profile in Qt 6.4 and clicking build? When I do so, I get the following error::-1: error: No rule to make target 'install'. Stop.What file is this install target supposed to be in?
This is the.profile:CONFIG += \ enable_decoder_1d_barcodes \ enable_decoder_qr_code \ enable_decoder_data_matrix \ enable_decoder_aztec \ enable_decoder_pdf17 \ enable_encoder_qr_code \ #staticlib \ #qzxing_qml \ #qzxing_multimedia \ VERSION = 3.3 TARGET = QZXing TEMPLATE = lib include(QZXing-components.pri) DEFINES -= DISABLE_LIBRARY_FEATURESThe only thing QZXing mentions about building as a library is https://github.com/ftylitak/qzxing#compile-the-project-as-an-external-library.
-
I appreciate the response @jsulm.
Does building as a library in Qt mean opening the
QZXing.profile in Qt 6.4 and clicking build? When I do so, I get the following error::-1: error: No rule to make target 'install'. Stop.What file is this install target supposed to be in?
This is the.profile:CONFIG += \ enable_decoder_1d_barcodes \ enable_decoder_qr_code \ enable_decoder_data_matrix \ enable_decoder_aztec \ enable_decoder_pdf17 \ enable_encoder_qr_code \ #staticlib \ #qzxing_qml \ #qzxing_multimedia \ VERSION = 3.3 TARGET = QZXing TEMPLATE = lib include(QZXing-components.pri) DEFINES -= DISABLE_LIBRARY_FEATURESThe only thing QZXing mentions about building as a library is https://github.com/ftylitak/qzxing#compile-the-project-as-an-external-library.
@gween said in How to use QZXing with cmake Qt 6.4:
TEMPLATE = lib
It is already built as library.
To make it properly with QMake you should create a https://wiki.qt.io/SUBDIRS_-_handling_dependencies project. You then add qzxing as one subproject and your actualy project as another one. Then in your project you add qzxing as dependency (see "Defining Project Dependencies: .depends attributes" chapter in the link above). -
@jsulm the subdirs link you sent makes sense for QMake, but does this work with CMake since I'm using Qt 6.4? My current project doesn't have a
.profile, only aCMakeLists.txtfile. Does thesubdirs"pattern" apply to projects that only haveCMakeLists.txt? I.e. is there aDefining Project Dependencies: .depends attributestype documentation for Qt 6.4 with cmake?The QZXing repo does have a
CMakeLists.txtfile, https://github.com/ftylitak/qzxing/blob/master/src/CMakeLists.txt, in itssrcdir. Which is why I thought I'd just be able to add the repo as a subdirectory to my main project, then use some cmake function, such asadd_subdirectory(), to reference the.hand.cppfiles. -
@jsulm's answer is correct:
You could build qzxing as a library and then link this library to your project using target_link_libraries.
This was my complete misunderstanding of cmake and how it works.
# with qzxing/src copied to my project as QZXing add_subdirectory(./QZXing/) target_link_libraries(${PROJECT_NAME} qzxing)My misunderstanding was from two things:
- I thought the command
add_subdirectory()was the only thing that should have been needed - That I had to use the library name that is specified in the
QZXing/CMakeLists.txt, which, from this commandadd_library(qzxing "" ${SOURCES})isqzxing.
- I thought the command
-
@jsulm's answer is correct:
You could build qzxing as a library and then link this library to your project using target_link_libraries.
This was my complete misunderstanding of cmake and how it works.
# with qzxing/src copied to my project as QZXing add_subdirectory(./QZXing/) target_link_libraries(${PROJECT_NAME} qzxing)My misunderstanding was from two things:
- I thought the command
add_subdirectory()was the only thing that should have been needed - That I had to use the library name that is specified in the
QZXing/CMakeLists.txt, which, from this commandadd_library(qzxing "" ${SOURCES})isqzxing.
- I thought the command