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. How to use 3rd party library to QT Creator?
Forum Updated to NodeBB v4.3 + New Features

How to use 3rd party library to QT Creator?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 9.5k Views 2 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.
  • faithinkingF Offline
    faithinkingF Offline
    faithinking
    wrote on last edited by faithinking
    #1

    To smart ass/smarty pant who only tell people to google or search forum: Don't even bother about that! I did my research, either googling or searching this forum. I wouldn't post a question until it is a last resort.

    I'm a newbie in QT using Windows environment. I'm trying to use a 3rd party library, namely Stanford C++ Library, for my C++ programming . Certainly I googled and found this article below.

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

    The trouble is that with all the instructions of qmake command lines given to me, I don't know how to invoke qmake console from QT creator in the first place!!! So I googled, but the tutorial below seems to assume that the user already has the qmake console opened. So I didn't get anywhere with this. How do I start the qmake console in Windows?

    http://doc.qt.io/qt-5/qmake-tutorial.html

    I also tried following the instruction, which was to add library from QT creator. However, the library given to me doesn't have any *.lib file, which QT creator keeps prompting me about. This again doesn't help me.

    http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html

    Ideally, I personally prefer incorporating the 3rd party library using GUI rather than command lines and have the 3rd party library automatically available whenever I start a new project. Please let me know how to do that.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      The Sample project included adds the sources directly to the final project. not a fan of this approach but that's what they are using.

      If you want to go this way just unpack the contents of StanfordCPPLib in your project folder and all all the files (Right click on the project name in QtCreator and add existing files). This is done in the sample project by these lines:

      SOURCES += $$PWD/lib/StanfordCPPLib/*.cpp
      SOURCES += $$PWD/lib/StanfordCPPLib/stacktrace/*.cpp
      HEADERS += $$PWD/lib/StanfordCPPLib/*.h
      HEADERS += $$PWD/lib/StanfordCPPLib/private/*.h
      HEADERS += $$PWD/lib/StanfordCPPLib/stacktrace/*.h
      

      Alternatively you can create a library project in QtCreator and add all the files to it and compile it, this will create the .lib files the tutorials refer to

      P.S.

      To smart ass/smarty pant who only tell people to google or search forum: Don't even bother about that! I did my research, either googling or searching this forum. I wouldn't post a question until it is a last resort.

      This is a bit aggressive, no need to be rude on your first post

      How do I start the qmake console in Windows?

      Just open cmd (start->type cmd and press enter) and then run qtenv2.bat from the bin folder of Qt, for example C:\Qt\5.7\msvc2013\bin\qtenv2.bat
      QtCreator calls qmake and make every time you click build

      "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

      faithinkingF 1 Reply Last reply
      1
      • VRoninV VRonin

        The Sample project included adds the sources directly to the final project. not a fan of this approach but that's what they are using.

        If you want to go this way just unpack the contents of StanfordCPPLib in your project folder and all all the files (Right click on the project name in QtCreator and add existing files). This is done in the sample project by these lines:

        SOURCES += $$PWD/lib/StanfordCPPLib/*.cpp
        SOURCES += $$PWD/lib/StanfordCPPLib/stacktrace/*.cpp
        HEADERS += $$PWD/lib/StanfordCPPLib/*.h
        HEADERS += $$PWD/lib/StanfordCPPLib/private/*.h
        HEADERS += $$PWD/lib/StanfordCPPLib/stacktrace/*.h
        

        Alternatively you can create a library project in QtCreator and add all the files to it and compile it, this will create the .lib files the tutorials refer to

        P.S.

        To smart ass/smarty pant who only tell people to google or search forum: Don't even bother about that! I did my research, either googling or searching this forum. I wouldn't post a question until it is a last resort.

        This is a bit aggressive, no need to be rude on your first post

        How do I start the qmake console in Windows?

        Just open cmd (start->type cmd and press enter) and then run qtenv2.bat from the bin folder of Qt, for example C:\Qt\5.7\msvc2013\bin\qtenv2.bat
        QtCreator calls qmake and make every time you click build

        faithinkingF Offline
        faithinkingF Offline
        faithinking
        wrote on last edited by
        #3

        @VRonin I'm still having trouble getting qmake to run in console. I tried running qtenv2.bat and it says... echo off... Setting up environment for Qt usage...

        Then I tried typing those commands and it's telling me that those commands are not recognized. What am I missing?

        VRoninV 1 Reply Last reply
        0
        • V Offline
          V Offline
          VRHans
          wrote on last edited by
          #4

          @faithinking Clearly you are frustrated :) - that's understandable.

          I can show you what I did to add a 3rd party library to my Qt project.

          I added the following to my *.pro file which I edited inside of QtCreator.

          unix: {
                  LIBS += -lcurl
          
                  debug {
                  LIBS += ~/myproject/3rdParty/Lib/Debug/x64/libJSONSpiritLib.a
                  }
                  release {
                  LIBS += ~/myproject/3rdParty/Lib/Release/x64/libJSONSpiritLib.a
                  }
          }
          

          The code above delineates that on unix, qmake should include the curl library, and if I'm building for debug, use a particular JSON Spirit library, and if release, use a different one.

          Tell QtCreator to run qmake and away you go.

          I'm pretty sure you can do the same thing on windows using - "windows: {"

          Hope that helps. If that's not what you're looking to do, apologies.

          1 Reply Last reply
          0
          • faithinkingF faithinking

            @VRonin I'm still having trouble getting qmake to run in console. I tried running qtenv2.bat and it says... echo off... Setting up environment for Qt usage...

            Then I tried typing those commands and it's telling me that those commands are not recognized. What am I missing?

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

            @faithinking said:

            those commands are not recognized.

            Which commands? if it's the SOURCES += etc. it's because they go in the .pro file

            I think the safest route for you would be to download the sample project unpack it, open it with qt creator, remove the files you don't need and add your code (basically edit the existing project instead of starting from scratch)

            "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

            faithinkingF 1 Reply Last reply
            0
            • blumfB Offline
              blumfB Offline
              blumf
              wrote on last edited by
              #6

              Had this problem in Windows, here's my solution:

              1. Go to the 'Options' dialog, select the 'Build & Run' page and the 'Kits' tab.
              2. Select your kit (e.g. 'Desktop Qt 5.6.1... blah')
              3. 'Change...' the 'Environment' option, add in something like the following:
              CPATH=C:\path\to\mylib\include
              LIBRARY_PATH=C:\path\to\mylib\lib
              PATH=C:\path\to\mylib\lib;${PATH}
              
              1. In your project's .pro file add:
              QMAKE_LIBDIR += $$(LIBRARY_PATH)
              
              1. Then you can just user LIBS += -lmylib.dll, or .lib, whatever.

              Far from ideal, and there are a few bits that could be improved upon, but seems to be the best way to add on third-party libs to QT Creator.

              1 Reply Last reply
              -1
              • VRoninV VRonin

                @faithinking said:

                those commands are not recognized.

                Which commands? if it's the SOURCES += etc. it's because they go in the .pro file

                I think the safest route for you would be to download the sample project unpack it, open it with qt creator, remove the files you don't need and add your code (basically edit the existing project instead of starting from scratch)

                faithinkingF Offline
                faithinkingF Offline
                faithinking
                wrote on last edited by
                #7

                @VRonin
                Thanks you for your patience. I really do want to learn typing in commands, but I'm practically clueless about it. Below is what I did in cmd... Please help. I would really like to follow what the tutorial is suggesting in case of any future 3rd party libraries.

                Microsoft Windows [Version 6.1.7601]
                Copyright (c) 2009 Microsoft Corporation. All rights reserved.

                C:>cd C:\Users\roger.chu>cd C:\Qt\Qt5.7.0\5.7\mingw53_32\bin

                C:\Qt\Qt5.7.0\5.7\mingw53_32\bin>qtenv2.bat

                C:\Qt\Qt5.7.0\5.7\mingw53_32\bin>echo off
                Setting up environment for Qt usage...

                C:\Qt\Qt5.7.0\5.7\mingw53_32>SOURCES +=C:\Qt\Qt5.7.0\5.7\Src\StanfordCPPLib*.cpp
                'SOURCES' is not recognized as an internal or external command,
                operable program or batch file.

                VRoninV 1 Reply Last reply
                0
                • faithinkingF faithinking

                  @VRonin
                  Thanks you for your patience. I really do want to learn typing in commands, but I'm practically clueless about it. Below is what I did in cmd... Please help. I would really like to follow what the tutorial is suggesting in case of any future 3rd party libraries.

                  Microsoft Windows [Version 6.1.7601]
                  Copyright (c) 2009 Microsoft Corporation. All rights reserved.

                  C:>cd C:\Users\roger.chu>cd C:\Qt\Qt5.7.0\5.7\mingw53_32\bin

                  C:\Qt\Qt5.7.0\5.7\mingw53_32\bin>qtenv2.bat

                  C:\Qt\Qt5.7.0\5.7\mingw53_32\bin>echo off
                  Setting up environment for Qt usage...

                  C:\Qt\Qt5.7.0\5.7\mingw53_32>SOURCES +=C:\Qt\Qt5.7.0\5.7\Src\StanfordCPPLib*.cpp
                  'SOURCES' is not recognized as an internal or external command,
                  operable program or batch file.

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

                  @faithinking That's not how it works. The general concept is to create a file (the .pro file) that has all the configuration to build the project in it then go in the folder where that file is and call qmake this will generate the makefiles that you then can execute calling make (nmake on MSVC)

                  see http://doc.qt.io/qt-5/qmake-project-files.html

                  "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

                  faithinkingF 1 Reply Last reply
                  0
                  • VRoninV VRonin

                    @faithinking That's not how it works. The general concept is to create a file (the .pro file) that has all the configuration to build the project in it then go in the folder where that file is and call qmake this will generate the makefiles that you then can execute calling make (nmake on MSVC)

                    see http://doc.qt.io/qt-5/qmake-project-files.html

                    faithinkingF Offline
                    faithinkingF Offline
                    faithinking
                    wrote on last edited by
                    #9

                    @VRonin
                    So do you mean I type in those "commands" in the *.pro file rather than a console? How do I execute the *.pro then? I think I need more of a step-by-step tutorial with screenshots and highlighted indicators.

                    1 Reply Last reply
                    0
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #10

                      VoidRealms on youtube has decent toutorials, see, for example: https://www.youtube.com/watch?v=VLYN99a2tKc&index=72&list=PL2D1942A4688E9D63

                      "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

                      • Login

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