Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to use QZXing with cmake Qt 6.4
Qt 6.12 LTS is out! See what's new in the release blog

How to use QZXing with cmake Qt 6.4

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 3 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gween
    wrote on last edited by
    #1

    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 .cpp files 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).

    jsulmJ 1 Reply Last reply
    0
    • G gween

      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 .cpp files 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).

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @gween You could build qzxing as a library and then link this library to your project using target_link_libraries.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gween
        wrote on last edited by gween
        #3

        I appreciate the response @jsulm.

        Does building as a library in Qt mean opening the QZXing.pro file 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 .pro file:

        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_FEATURES
        

        The only thing QZXing mentions about building as a library is https://github.com/ftylitak/qzxing#compile-the-project-as-an-external-library.

        jsulmJ 1 Reply Last reply
        0
        • G gween

          I appreciate the response @jsulm.

          Does building as a library in Qt mean opening the QZXing.pro file 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 .pro file:

          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_FEATURES
          

          The only thing QZXing mentions about building as a library is https://github.com/ftylitak/qzxing#compile-the-project-as-an-external-library.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gween
            wrote on last edited by gween
            #5

            @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 .pro file, only a CMakeLists.txt file. Does the subdirs "pattern" apply to projects that only have CMakeLists.txt? I.e. is there a Defining Project Dependencies: .depends attributes type documentation for Qt 6.4 with cmake?

            The QZXing repo does have a CMakeLists.txt file, https://github.com/ftylitak/qzxing/blob/master/src/CMakeLists.txt, in its src dir. 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 as add_subdirectory(), to reference the .h and .cpp files.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gween
              wrote on last edited by
              #6

              @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:

              1. I thought the command add_subdirectory() was the only thing that should have been needed
              2. That I had to use the library name that is specified in the QZXing/CMakeLists.txt, which, from this command add_library(qzxing "" ${SOURCES}) is qzxing.
              niqtN 1 Reply Last reply
              0
              • G gween

                @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:

                1. I thought the command add_subdirectory() was the only thing that should have been needed
                2. That I had to use the library name that is specified in the QZXing/CMakeLists.txt, which, from this command add_library(qzxing "" ${SOURCES}) is qzxing.
                niqtN Offline
                niqtN Offline
                niqt
                wrote on last edited by
                #7

                @gween How do you use QZing? His CMake use QT5

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt
                • Unsolved