Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Use QZXing in qml
Forum Updated to NodeBB v4.3 + New Features

Use QZXing in qml

Scheduled Pinned Locked Moved Solved QML and Qt Quick
13 Posts 4 Posters 5.4k Views 3 Watching
  • 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.
  • M MHermann

    Hi all,

    at the moment I am trying to use QZXing in my qml.
    But I am failing.
    If I try to compile I get the following error: "undefined reference to 'QZXing::registerQMLTypes()'"
    But decoding the qr code of an image in main() works.

    What I have done so far:

    • Downloaded QZXing source and compiled it to get libQZXing.so.

    • xxx.pro file:

      QT += core gui qml quick widgets multimedia
      ...
      LIBS += -L$$PWD/QZXing/ -lQZXing
      INCLUDEPATH += $$PWD/QZXing
      DEPENDPATH += $$PWD/QZXing
      
    • main.cpp:

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QZXing.h>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
          QGuiApplication app(argc, argv);
      
          QZXing::registerQMLTypes();
          QQmlApplicationEngine engine;
          engine.load(QUrl(QLatin1String("qrc:/main.qml")));
          if (engine.rootObjects().isEmpty())
              return -1;
      
          QImage qrCodeimageToDecode("/xxx/qrcode.png");
          QZXing decoder;
          decoder.setDecoder(QZXing::DecoderFormat_QR_CODE);
          QString resultQrCode = decoder.decodeImage(qrCodeimageToDecode);
      
          return app.exec();
      }
      

    Any ideas what I am doing wrong?

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #2

    @MHermann said in Use QZXing as library in qml:

    Any ideas what I am doing wrong?

    are you sure the libQZXing.so relies in $$PWD/QZXing/ ??

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    M 2 Replies Last reply
    0
    • raven-worxR raven-worx

      @MHermann said in Use QZXing as library in qml:

      Any ideas what I am doing wrong?

      are you sure the libQZXing.so relies in $$PWD/QZXing/ ??

      M Offline
      M Offline
      MHermann
      wrote on last edited by
      #3

      @raven-worx : Yes, I compiled it and copied it there.

      1 Reply Last reply
      1
      • raven-worxR raven-worx

        @MHermann said in Use QZXing as library in qml:

        Any ideas what I am doing wrong?

        are you sure the libQZXing.so relies in $$PWD/QZXing/ ??

        M Offline
        M Offline
        MHermann
        wrote on last edited by MHermann
        #4

        @raven-worx :
        The three lines

        QZXing decoder;
        decoder.setDecoder(QZXing::DecoderFormat_QR_CODE);
        QString resultQrCode = decoder.decodeImage(qrCodeimageToDecode);
        

        are executing without problems. And they are also used from libQZXing.so.

        raven-worxR 1 Reply Last reply
        1
        • M MHermann

          @raven-worx :
          The three lines

          QZXing decoder;
          decoder.setDecoder(QZXing::DecoderFormat_QR_CODE);
          QString resultQrCode = decoder.decodeImage(qrCodeimageToDecode);
          

          are executing without problems. And they are also used from libQZXing.so.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #5

          @MHermann

          are executing without problems. And they are also used from libQZXing.so.

          Yes i overread that.

          seems the QZXING_QML macro definition is missing.
          Recompile the lib with CONFIG += qzxing_qml

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          M 1 Reply Last reply
          1
          • raven-worxR raven-worx

            @MHermann

            are executing without problems. And they are also used from libQZXing.so.

            Yes i overread that.

            seems the QZXING_QML macro definition is missing.
            Recompile the lib with CONFIG += qzxing_qml

            M Offline
            M Offline
            MHermann
            wrote on last edited by MHermann
            #6

            @raven-worx :
            I added the line

            CONFIG += qzxing_qml
            

            to QZXing.pro and compiled the lib again.

            I copied the new *.so files to my directory.
            But it behaves exactly the same...
            "undefined reference to `QZXing::registerQMLTypes()'"

            I forgot to mention, that I also added additional arguments in my project:

            DEFINES+=QZXING_QML DEFINES+=QML_MULTIMEDIA
            

            Any more ideas?

            raven-worxR 1 Reply Last reply
            0
            • M MHermann

              @raven-worx :
              I added the line

              CONFIG += qzxing_qml
              

              to QZXing.pro and compiled the lib again.

              I copied the new *.so files to my directory.
              But it behaves exactly the same...
              "undefined reference to `QZXing::registerQMLTypes()'"

              I forgot to mention, that I also added additional arguments in my project:

              DEFINES+=QZXING_QML DEFINES+=QML_MULTIMEDIA
              

              Any more ideas?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #7

              @MHermann said in Use QZXing as library in qml:

              Any more ideas?

              No, this seemed pretty much the cause for issue to me.

              Alternatively - if its's an option for you - you could add include($$PWD/QZXing/src/QZXing.pri (and also add CONFIG += qzxing_qml) to your application's .pro file. Then QZXing is compiled into your binary directly.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              M 1 Reply Last reply
              2
              • raven-worxR raven-worx

                @MHermann said in Use QZXing as library in qml:

                Any more ideas?

                No, this seemed pretty much the cause for issue to me.

                Alternatively - if its's an option for you - you could add include($$PWD/QZXing/src/QZXing.pri (and also add CONFIG += qzxing_qml) to your application's .pro file. Then QZXing is compiled into your binary directly.

                M Offline
                M Offline
                MHermann
                wrote on last edited by
                #8

                @raven-worx :

                This could also be a solution. But this would not be my preferred solution...
                That would mean that the whole QZXing source code will be compiled too, each time I am compiling my own source code.
                Or is it possible to exclude this from the compiling process and compile it only once?

                raven-worxR 1 Reply Last reply
                1
                • M MHermann

                  @raven-worx :

                  This could also be a solution. But this would not be my preferred solution...
                  That would mean that the whole QZXing source code will be compiled too, each time I am compiling my own source code.
                  Or is it possible to exclude this from the compiling process and compile it only once?

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by raven-worx
                  #9

                  @MHermann
                  it gets only recompiled when it needs to (when a source file changes, etc)

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  M 1 Reply Last reply
                  1
                  • raven-worxR raven-worx

                    @MHermann
                    it gets only recompiled when it needs to (when a source file changes, etc)

                    M Offline
                    M Offline
                    MHermann
                    wrote on last edited by
                    #10

                    @raven-worx :

                    I added the QZXing source code via

                    include($$PWD/QZXing/src/QZXing.pri
                    

                    Now it is working.

                    1 Reply Last reply
                    2
                    • lukas_kosinskiL Offline
                      lukas_kosinskiL Offline
                      lukas_kosinski
                      wrote on last edited by
                      #11

                      Hi! If your project is based on C++, consider using SCodes. SCodes uses latest ZXing C++ port. It also allows you to generate QR/Bar codes. You can read more about it here.

                      ekkescornerE 1 Reply Last reply
                      1
                      • lukas_kosinskiL lukas_kosinski

                        Hi! If your project is based on C++, consider using SCodes. SCodes uses latest ZXing C++ port. It also allows you to generate QR/Bar codes. You can read more about it here.

                        ekkescornerE Offline
                        ekkescornerE Offline
                        ekkescorner
                        Qt Champions 2016
                        wrote on last edited by
                        #12

                        @lukas_kosinski unfortunately SCodes only supports Code128 and QR

                        ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                        5.15 --> 6.9 https://t1p.de/ekkeChecklist
                        QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                        lukas_kosinskiL 1 Reply Last reply
                        0
                        • ekkescornerE ekkescorner

                          @lukas_kosinski unfortunately SCodes only supports Code128 and QR

                          lukas_kosinskiL Offline
                          lukas_kosinskiL Offline
                          lukas_kosinski
                          wrote on last edited by
                          #13

                          @ekkescorner I worked on that and now it supports much more formats. Currently it's a PR opened, but it should be soon merged:
                          https://github.com/scytheStudio/SCodes/pull/11

                          Sorry that I add the comment to a quite old post. I simply wanted people to know it and not be misled.

                          1 Reply Last reply
                          2

                          • Login

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