# How to use 3rd party library to QT Creator?

• 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.

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

• # @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]

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.

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

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