Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem Linking a Qt Gui with a c++ project
QtWS25 Last Chance

Problem Linking a Qt Gui with a c++ project

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 4.4k 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.
  • M Offline
    M Offline
    Mohamed Fouzi
    wrote on last edited by Mohamed Fouzi
    #1

    Hello everyone !
    My teacher gave me a c++ code (zcl: Zigbee Cluster Library), an asked me to make a user interface for this code.
    -1- The code given can only be compiled with the "mvs nativex64 command prompt", and it's not a structured project, only a .cpp file using a header and a library + a .dll
    -2- After compiling, there is a .exe file
    And here is my problem:
    How to link my Qt user interface with the code given ?
    Should i copy/paste the c++ code into the Qt project ?! And if so, how to compile it to make it run ?! (because i have tried compiling it with the same "command line", but without success.. (maybe i have to set the "environment variable" for Qt) ?!
    Or should i use the ".exe" from my Qt Gui ?! And if so, how to do it since i want to link "features" from the .exe file to the user interface ?!
    I'm open to any other suggestions, assuming you have understood my messy explanation.

    VRoninV J.HilkJ 2 Replies Last reply
    0
    • M Mohamed Fouzi

      Hello everyone !
      My teacher gave me a c++ code (zcl: Zigbee Cluster Library), an asked me to make a user interface for this code.
      -1- The code given can only be compiled with the "mvs nativex64 command prompt", and it's not a structured project, only a .cpp file using a header and a library + a .dll
      -2- After compiling, there is a .exe file
      And here is my problem:
      How to link my Qt user interface with the code given ?
      Should i copy/paste the c++ code into the Qt project ?! And if so, how to compile it to make it run ?! (because i have tried compiling it with the same "command line", but without success.. (maybe i have to set the "environment variable" for Qt) ?!
      Or should i use the ".exe" from my Qt Gui ?! And if so, how to do it since i want to link "features" from the .exe file to the user interface ?!
      I'm open to any other suggestions, assuming you have understood my messy explanation.

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @Mohamed-Fouzi said in Problem Linking a Qt Gui with a c++ project:

      only a .cpp file using a header

      What do those files contain?

      a library + a .dll

      a dll is a library (dll = dinamically linked library) so what do you mean?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • M Mohamed Fouzi

        Hello everyone !
        My teacher gave me a c++ code (zcl: Zigbee Cluster Library), an asked me to make a user interface for this code.
        -1- The code given can only be compiled with the "mvs nativex64 command prompt", and it's not a structured project, only a .cpp file using a header and a library + a .dll
        -2- After compiling, there is a .exe file
        And here is my problem:
        How to link my Qt user interface with the code given ?
        Should i copy/paste the c++ code into the Qt project ?! And if so, how to compile it to make it run ?! (because i have tried compiling it with the same "command line", but without success.. (maybe i have to set the "environment variable" for Qt) ?!
        Or should i use the ".exe" from my Qt Gui ?! And if so, how to do it since i want to link "features" from the .exe file to the user interface ?!
        I'm open to any other suggestions, assuming you have understood my messy explanation.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @Mohamed-Fouzi

        What I think you're saying is, you have a precompiled c/c++ libary and a header file to access the functions in your libary?

        And now you look for a way to access those functions from QT?

        if that is the case, I can give you a short example from a project of mine, where I did exactly that with libusb

        In you Project-File,

        you'll have to add the lib-header file, include the path to the folder of your libary and add it to your LIBS:

        SOURCES += main.cpp\
                mainwindow.cpp
        
        HEADERS  += mainwindow.h \
            libusb.h
        
        FORMS    += mainwindow.ui
        
        INCLUDEPATH += C:/Software/libUSB/include
        
        LIBS += -LC:/Software/libUSB/MinGW32/dll\
                libusb-1.0
        

        in your UI-Class mainwindow in this example you include the *h-file:

        #include <QMainWindow>
        #include <QIODevice>
        ....
        #include "libusb.h"
        

        Now you can simply access the functions of your libary by calling them . e.g.:

        r = libusb_init(&ctx); //initialize a library session
        ...
        libusb_exit(ctx); //close the session
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        3
        • M Offline
          M Offline
          Mohamed Fouzi
          wrote on last edited by
          #4

          @J-Hilk
          Thank you for your answer,. I think that you get exactly what i want to do. I will try that immediatly, even if i have some questions to ask.
          For example :
          -1- The "LIBS += -LC:/Software/libUSB/MinGW32/dll
          libusb-1.0"
          Correct me if i'm wrong. You added the library path, (C:/Software/libUSB/MinGW32/dll) and the name of the library (libusb-1.0), is that right ?!
          -2- The "-L" before the path of the library isn't a mistake, just to be sure ?!

          And last but not least, when i tried to compile the c/c++ code, i was able to do it only with the vs2015 x64 compiler, when i tried with "gcc", it didn't worked.. So if i will try to compile the Qt project with those files, would there be a problem ?!
          Thank you.

          @VRonin : The .cpp files contains the logic of the program and the .header contains the interface.
          For the (dll = dynamic library), i know that. But, i think i didn't explain myself well.
          My teacher gave me a code already precompiled, but also gave me these three folders in case i wanted to modify the code and compile it again.

          folder1 : Windows-gcc_64bits, contains:

          TestZCL.exe
          zcl.a
          zcl.def
          zcl.dll

          folder2 : Windows-msvc_64bits, contains:

          licence.lic
          TestZCL.exe
          zcl.dll
          zcl.lib

          folder3 : Windows-msvc2013_64bits, contains:

          TestZCL.exe
          zcl.dll
          zcl.lib

          I hope you understand me better now.

          J.HilkJ 1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            http://doc.qt.io/qt-5/third-party-libraries.html

            the header is the include

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            2
            • M Offline
              M Offline
              Mohamed Fouzi
              wrote on last edited by
              #6

              @VRonin, @J-Hilk : i would like to thank both of you, it was helpful. With your help, i managed to get the code working in Qt.

              However, i have one last question if you permit me.

              When i was frustrated (:p), i tried to get the code working in Visual Studio, i struggled a lot.

              In the beginning stages: The c/c++ code (given by the teacher) worked only with the prompt command, but, hopefully, putting the right .dll in the right folders (and changing the plateform configuration from Win32 to x64) helped me to run the code from VS directly. Unfortunately, the problem that i got start from here:

              -1- When i execute the c/c++ code "alone", it works like a charm. (adding the necessary libraries)
              -2- When i execute a Qt code form Visual Studio (using the add-on), it works also perfectly.

              But, when i "mix" the codes into one and try to execute, i get a lot of "Error LNK2001_ Unresolved External" and "Error LNK2019_Unresolved External", both refering to "Qt functions".

              I hope i was clear enough. Thank you again.

              VRoninV 1 Reply Last reply
              0
              • M Mohamed Fouzi

                @VRonin, @J-Hilk : i would like to thank both of you, it was helpful. With your help, i managed to get the code working in Qt.

                However, i have one last question if you permit me.

                When i was frustrated (:p), i tried to get the code working in Visual Studio, i struggled a lot.

                In the beginning stages: The c/c++ code (given by the teacher) worked only with the prompt command, but, hopefully, putting the right .dll in the right folders (and changing the plateform configuration from Win32 to x64) helped me to run the code from VS directly. Unfortunately, the problem that i got start from here:

                -1- When i execute the c/c++ code "alone", it works like a charm. (adding the necessary libraries)
                -2- When i execute a Qt code form Visual Studio (using the add-on), it works also perfectly.

                But, when i "mix" the codes into one and try to execute, i get a lot of "Error LNK2001_ Unresolved External" and "Error LNK2019_Unresolved External", both refering to "Qt functions".

                I hope i was clear enough. Thank you again.

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #7

                @Mohamed-Fouzi said in Problem Linking a Qt Gui with a c++ project:

                But, when i "mix" the codes into one and try to execute, i get a lot of "Error LNK2001_ Unresolved External" and "Error LNK2019_Unresolved External", both refering to "Qt functions".

                That's because the VSaddin hides the linking to Qt libraries and the calls to uic/moc/rcc if you start with a non-Qt-addin project you have to do all those things manually

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                M 1 Reply Last reply
                1
                • VRoninV VRonin

                  @Mohamed-Fouzi said in Problem Linking a Qt Gui with a c++ project:

                  But, when i "mix" the codes into one and try to execute, i get a lot of "Error LNK2001_ Unresolved External" and "Error LNK2019_Unresolved External", both refering to "Qt functions".

                  That's because the VSaddin hides the linking to Qt libraries and the calls to uic/moc/rcc if you start with a non-Qt-addin project you have to do all those things manually

                  M Offline
                  M Offline
                  Mohamed Fouzi
                  wrote on last edited by
                  #8

                  @VRonin said in Problem Linking a Qt Gui with a c++ project:

                  @Mohamed-Fouzi said in Problem Linking a Qt Gui with a c++ project:

                  But, when i "mix" the codes into one and try to execute, i get a lot of "Error LNK2001_ Unresolved External" and "Error LNK2019_Unresolved External", both refering to "Qt functions".

                  That's because the VSaddin hides the linking to Qt libraries and the calls to uic/moc/rcc if you start with a non-Qt-addin project you have to do all those things manually

                  The fact is, i'm getting those errors even if i've started a Qt-addin project, in which i've added the c/c++ code.

                  It seems like i have a new problem now, too.
                  You see, in this project, i use a Ubee device (Usb Zigbee Controller). And, when i execute the code without it plugged in, the code works (Ubee not found is displayed).
                  But when i plugged in the Ubee, and try to run the code, it is found, but it crashes immediatly.. Could it be related to the .dll files ?!

                  jsulmJ 1 Reply Last reply
                  0
                  • M Mohamed Fouzi

                    @VRonin said in Problem Linking a Qt Gui with a c++ project:

                    @Mohamed-Fouzi said in Problem Linking a Qt Gui with a c++ project:

                    But, when i "mix" the codes into one and try to execute, i get a lot of "Error LNK2001_ Unresolved External" and "Error LNK2019_Unresolved External", both refering to "Qt functions".

                    That's because the VSaddin hides the linking to Qt libraries and the calls to uic/moc/rcc if you start with a non-Qt-addin project you have to do all those things manually

                    The fact is, i'm getting those errors even if i've started a Qt-addin project, in which i've added the c/c++ code.

                    It seems like i have a new problem now, too.
                    You see, in this project, i use a Ubee device (Usb Zigbee Controller). And, when i execute the code without it plugged in, the code works (Ubee not found is displayed).
                    But when i plugged in the Ubee, and try to run the code, it is found, but it crashes immediatly.. Could it be related to the .dll files ?!

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

                    @Mohamed-Fouzi If it crashes you should debug to see where it is crashing.

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

                    1 Reply Last reply
                    0
                    • M Mohamed Fouzi

                      @J-Hilk
                      Thank you for your answer,. I think that you get exactly what i want to do. I will try that immediatly, even if i have some questions to ask.
                      For example :
                      -1- The "LIBS += -LC:/Software/libUSB/MinGW32/dll
                      libusb-1.0"
                      Correct me if i'm wrong. You added the library path, (C:/Software/libUSB/MinGW32/dll) and the name of the library (libusb-1.0), is that right ?!
                      -2- The "-L" before the path of the library isn't a mistake, just to be sure ?!

                      And last but not least, when i tried to compile the c/c++ code, i was able to do it only with the vs2015 x64 compiler, when i tried with "gcc", it didn't worked.. So if i will try to compile the Qt project with those files, would there be a problem ?!
                      Thank you.

                      @VRonin : The .cpp files contains the logic of the program and the .header contains the interface.
                      For the (dll = dynamic library), i know that. But, i think i didn't explain myself well.
                      My teacher gave me a code already precompiled, but also gave me these three folders in case i wanted to modify the code and compile it again.

                      folder1 : Windows-gcc_64bits, contains:

                      TestZCL.exe
                      zcl.a
                      zcl.def
                      zcl.dll

                      folder2 : Windows-msvc_64bits, contains:

                      licence.lic
                      TestZCL.exe
                      zcl.dll
                      zcl.lib

                      folder3 : Windows-msvc2013_64bits, contains:

                      TestZCL.exe
                      zcl.dll
                      zcl.lib

                      I hope you understand me better now.

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      Hi, let me answer a few questions you had:

                      @Mohamed-Fouzi said in Problem Linking a Qt Gui with a c++ project:

                      -1- The "LIBS += -LC:/Software/libUSB/MinGW32/dll
                      libusb-1.0"
                      Correct me if i'm wrong. You added the library path, (C:/Software/libUSB/MinGW32/dll) and the name of the library (libusb-1.0), is that right ?!

                      in a nutshell, yes. I like to write the actuall libary in a seperated line.Makes it easier, in case I have more to add later on, that have the same basic path.

                      -2- The "-L" before the path of the library isn't a mistake, just to be sure ?!

                      No it's not, its a flag for qmake to mark the following as a libary path.

                      And last but not least, when i tried to compile the c/c++ code, i was able to do it only with the vs2015 x64 compiler, when i tried with "gcc", it didn't worked.. So if i will try to compile the Qt project with those files, would there be a problem ?!
                      Thank you.

                      That really depends on what was used to create the libary. If its a pure c-libary you usually don't have to worry at all.
                      But if it is a c++ one you'll have to use the compiler for your project, that was also used for the libary. I believe that is way your teacher? gave you the source code of those. To not be limited to MSVC. Just recompile the lib using Qt and mingw and your good to go.


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Mohamed Fouzi
                        wrote on last edited by
                        #11

                        What do you mean by recompile the .lib ?! Note that for gcc. i have a "zcl.a" library (a static library).

                        I just compiled the same code with MinGW, and i get errors of type : "undefined reference" to all the functions of the library. Is there a solution ?!

                        jsulmJ 1 Reply Last reply
                        0
                        • M Mohamed Fouzi

                          What do you mean by recompile the .lib ?! Note that for gcc. i have a "zcl.a" library (a static library).

                          I just compiled the same code with MinGW, and i get errors of type : "undefined reference" to all the functions of the library. Is there a solution ?!

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

                          @Mohamed-Fouzi I guess this library is built using another compiler (not MinGW), right? This cannot work: you cannot mix binaries built with different compilers. If you want to use MinGW then you need to compile this library with MinGW as well - this is what @J-Hilk means.

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

                          1 Reply Last reply
                          2
                          • M Offline
                            M Offline
                            Mohamed Fouzi
                            wrote on last edited by
                            #13

                            Ok, i would like to thank both of you.
                            Guess i'll need to see how to compile a library with MinGW, then.

                            i'll keep you informed if there is any improvement.

                            EDIT: i finally managed to get the whole thing working. So, basically, since compiling from the command line, gave me no errors at all (even if the ZigBee device was pluged on), i asked myself if there would be some change to do in the "building and compiling" parts of Visual Studio.
                            So all i did, was to change the "plateform to x64" and the configuration to "release" version.
                            It seems the last change, "the release" was the most important, because when i did it, it worked perfectly.

                            So, i jumped to Qt and did the same (even i'm i'm sure i did it before, but didn't worked). So, with the kit using MSVC2015, and choose a release version, and tada, it worked also in Qt, there were no crashes at all.

                            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 Extensions
                            • Unsolved