Qt Creator / QMake Linker Libraries - c++

I'm using SFML, and I want to use Qt Creator in conjunction with it. When I'm compiling manually, I supply the following arguments to the linker -lsfmlsystem -lsfmlwindow.
How do I do this if I'm using Qt Creator and (I think) QMake?

Just add
LIBS += -L/path/to/sfml -lsfmlsystem -lsfmlwindow
to the .pro file.
You can open project files with QtCreator from the Projects view of the sidebar or searching for it via Ctrl-K. (BTW, the sidebar is not the list of icons down the left, it's the pane to the right of that which can be shown/hidden with Alt-0.)

Related

Use a QT Widget plugin using static qmake

i have built an QT GUI app using Visual Studio 2017 with Qt VS Tools extension and QT version 5.6 (the one provided by QT precompiled), using Qled widget plugin.
With this Default Dynamic Qt version, the app runs fine with the widget and i have no problems.
But now, i want to build the same app, but static, for use without dependencies.
So, i built QT 5.6 from source with -static parameter, to be more exact i follow this blog's guide. Here problems started to show up:
I tried to rebuild the widget plugin using the static qmake, but i got this error: "Project ERROR: Unknown module(s) in QT: designer"
I tried to use the plugin compiled by the dynamic qmake, and surprisingly, it built with success but the GUI app didn't open at all.
Its worth mentioning that i can use and build a simple default application using a qmake static build.
I think i need to add the Qt Designer Module, but i don't know how to do this, i even tried to rebuild qmake without the "-nomake tools" paramter, but got the same error building the plugin.
just don't build the plugin, you don't need it. Just add the qrc file, and the actual widget *.cpp and *.h file into your project
fix the linkage, delete the QDESIGNER_WIDGET_EXPORT in the *.h file inside your project
This comment managed to solved my problem, thanks to #PeterT

Using libraries with C++ and Qt

I am trying to use a library to generate barcode images inside a Qt/C++ app.
I've been looking at ZINT and ZXING, but I don't understand how would I use them inside my code.
If I download and compile the library, how do I call it afterwards? Could I set up the Qt makefile to compile it for the desired platform?
Thanks, and sorry for the broad question, I'm not very experienced in C++ projects.
In QT you usually include 3rd party libraries through the .pro file. Use the LIBS variable to tell QT where to find it.
Example lines from the QT docs:
TARGET = MyQtApp
TEMPLATE = app
INCLUDEPATH += 3rdparty/CatWhisperer/include
SOURCES += src/main.cpp
LIBS += -L"3rdparty/CatWhisperer/lib" -lCatWhisperer
If you're using Qt Creator, you can add libraries to your .pro by using a wizard provided by the IDE. Right-click your project in the project browser, click Add library... and, then, follow the wizard.
More details here: http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html

How to change Qt Creator build tool?

Is there anyway to change the build tool Qt Creator uses? Currently, Qt Creator has defaulted to the Qt5 version of qmake. I would like to use the Qt4 version of qmake, or the /usr/bin/make/ option. What are the steps needed to make this happen?
Go to Tools->Options->Build&Run
Then select Qt Versions tab. You can add qmake there by giving path manually
While building project you can select the respective toolchain as well. That can be done from left panel option project then select the configured toolchain.
Go to Project folder in the left sidebar (under the debug button). Then click 'Manage kits' and create a new kit including the Qt4 make path or change the qmake path of your current path for the qt4 one. The QMake is chosen under the tab QtVersions.

Qt Creator in Windows - How do I know which compiler is being used?

I'm running Qt Creator 3.1.1 in Windows. I have an existing Qt project and I'm trying to add the Boost library to it. I think I have the .pro file configured to correctly point to the .lib and .hpp folders. However, I still get a linking error when I compile: "LNK2019: unresolved external symbol".
From other things I've read, it looks like I need to make sure that my Boost was compiled with the same compiler I'm using to compile my Qt projects.
Here's the Boost build I installed: http://boost.teeks99.com/bin/1.55.0/boost_1_55_0-msvc-12.0-64.exe
Here's a screenshot of my Qt Creator About window:
And here's a screenshot of my Qt Creator compiler options:
How can I tell which compiler I'm using? It lists a whole bunch, but isn't very clear about which one is actually used. Also, please let me know if this could be a simple 64 vs 32 bit problem.
You're looking at the QtCreator settings -- what you want is your project settings. In the left sidebar, click Projects.
At the top of the project pane, the selected build options for the current target appear in a little box at the top. Hover your mouse cursor over the down arrow for the compiler and debugger details, you'll see something like this:

Configuring Qt Creator with executable and DLL project

I am new to QT Creator coming from Visual Studio. I have a session with two projects in it. One is a DLL with some classes that I intend to use for other purposes. The other is an executable console app that uses some of the classes from the DLL.
I currently have these two projects side by side in QT Creator. I can include the header files from the DLL in my EXE project using relative paths "../MyPrject/header.h". But how do I get QT Creator to link and then copy the DLL into the executable debug folder for debugging.
Am I doing this all wrong? Is there a better way? If it includes adding code to the .pro file, please include a link so that I can learn more.
You should make some dependencies between this projects.
opening both projects - you have done.
on editor view, right click on exe-project and select add library...
follow creator hints to add it.
2nd option: you can make subprojects. follow QtCreator: Creating Projects from documentation (help view in Qt Creator)
GwyenBleidD provided a good starting point for including DLLs.
I however, have made a habit out of modifying the .pro file directly here and honestly I prefer to modify the .pro file in the event that something goes haywire.
Suppose I wanted to use the winsock DLL.
In the .pro file, I'd first specify the .dll's corresponding .lib file:
# WinSock2 library (ws2_32.lib file)
LIBS += -lws2_32
# Path to the WinSock2 library
LIBS += -L"c:/mylibraries/"
Additionally, you'll need to specify the include path to the header files here:
INCLUDEPATH += "c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/INCLUDE"
Thirdly, in my code I'd have to make sure to include the headers for it:
// I ASSUME it'll be found under something like the
// Visual Studio/VC/INCLUDE directory mentioned above.
#include <winsock2.h>
Lastly, you need to ensure that your application can find the .dll file, typically pointed to using the %PATH% environment variable.
With regards to your setup, I'd make sure that your sub-projects are configured so that the library compiles FIRST (obviously). And then ensure that the LIBS variable in your .Pro project points correctly to your .lib destination according to the build configuration (debug|release).
Qt's PRO (qmake) isn't as terrible as some make it out to be. Just give it a solid half-hour to an hour and you'll get the hang of it. I assume though that you have a solid understanding of libs and DLLs and what not.
http://qt-project.org/doc/qt-5.0/qtdoc/qmake-manual.html
The right way is to switch on CMake based project and keep exe and dll within one root project. The main benefit of this decision is IDE independent approach: you can use Qt Creator, CLion, Visual Studio without any changes in project definition. As the start point consider to see the example project https://github.com/anatoly-spb/cmake_exe_dll