how to link Qt with a visual studio c++ application project? - c++

I have Qt 5.12.0 in a folder.
I need to create a dll and/or a bin project that can connect with a QML program.
My problem is that the vs project can't find the Qt files I need.
#include <QGuiApplication>
does not work.
This topic is the continuity of this one
How to link libraries to a project on visual studio? where I shared my problems with linking my dll with my bin project and to link Qt.
So I use a batch file to set the environment variable before launching visual studio. I use these variables to get the path to the Qt include folder, Qt lib etc.
Here is what I tried.
include the directory that contains the headers I need (I guess) :
configuration properties -> C/C++ -> General -> other include directories ->$(QT_INC)/. QT_INC is the path to the include folder. I also tried to write $(QT_INC)/* and $(QT_INC)/QtGui/. In any case,
#include <QGuiApplication>
couldn't compile.
i also added the path to the library folder :
linker->General->Additional library directories->$(QT_LIB)/
and some lib files in :
linker->entry->additionnal dependencies->Qt5Quick.lib;Qt5Gui;lib;Qt5Core.lib
none of these steps creates any error. It just doesn't help to find QGuiApplication.h nor QObject or anything I need.
I know my paths are correct and that using the environment variable like this works as I linked my dll using this method, and because wrong paths generates errors.
How to add Qt to my solution or to a project ?
thanks in advance

It works. The path was incorrect. There were "/" instead of "\" I think. And a synthax error in the batch file.
It's possible to add the header files of Qt by including the path in the properties.
include just the directory include of the Qt folder. Then, include headers again and again until all the errors are gone.
only for QGuiApplication, I need to include this
#include <QtGui/qtguiglobal.h>
#include <QtGui/qcoreapplication.h>
etc. all the includes of the beggining of QGuiApplication.h actually
here is the link to my other post I made about linking Qt to visual studio. How to link libraries to a project on visual studio? The problem was about the path to the dll.

Related

How to create library that uses some other libraries?

I'm trying to create a graphic library (nothing serious, just to learn stuff). In Visual Studio I have one solution and two projects in it - dll and exe. For window management I use GLFW library. In my own window class I want to have a private memeber of GLFW Window structure. The problem is that my exe project doesn't know what GLFW is - it doesn't know where to find #include <glfw/glfw3>.
My question is - what's the proper way to create such library that uses other libraries? Setting the exe project to include all those libraries doesn't sound like a good idea to me.
Since you are using visual studio, then Microsofts documentation is a great place to get information. https://learn.microsoft.com/en-us/cpp/build/dlls-in-visual-cpp?view=vs-2019 they have a description on DLL’s and how to create them and also how to link DLL’s to projects.
Thanks to #Manuel I figured out how to do it: both - dll and exe projects, have to include libraries' header files.
My solution: in dll I use precompiled headers so all libraries' header files are included in that file with a relative path. In dll project settings I put proper paths so any libraries files will know how to find their headers. What's important is that my exe project includes one header file from my dll and that file include precompiled header so exe project 'knows' everything it needs about libraries.
Thanks again #Manuel for your help!

How to add Qt libraries to visual studio

I have a source with VC++ 2017
I receive the error "Error C1083 Cannot open include file: 'QtCore/QMap': No such file or directory " when i try compile the project.
I download Qt libraries and add to Include project but the problem exist.
Which directory of Qt of i had to add to project to resolve error?
this is header of my code that generate error
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QList>
You need to update your project. Go to the project properties by right-clicking on it in Solution Explorer and then select Properties. Then:
In C/C++->General->Additional Include Directories you must set the Qt installation include path;
In Linker->General->Additional Library Directories you must add the path of .libs files of your qt installation;
In Linker->Input->Additional Dependencies you must put the name of .lib files that you need in order to build the project.
If it's a Qt project, you should also have the Qt plugin installed, in order to work properly with moc and other Qt features.
In alternative (that I suggest) you can create a CMake project and open in in Visual Studio.

How do I include libraries to a project in Visual Studio?

I am a beginner on C++ and trying to learn about including libraries, and I haven't found documentation about it.
What are the ways of including libraries to a C++ project (Visual Studio). How do I implement them and which is the best way?
I was trying to include the SQLite library to a project. I tried to:
Include the header file in the include folder of the Visual Studio installation folder. It did appear in the External dependencies of my project, so I can do #include <sqlite3.h> without problems, but I don't know where I should put the implementation (a C file) and how to link it (is it in the linker>Input>Additional dependencies?).
Is it necessary that in order to include a library the file should be a .lib? Because I can't find the .lib for SQLite 3, do I have to include it in the lib folder of my Visual Studio installation?
Note: I am interested on the management of including a library in general. The SQLite 3 part is only because I took it as an example in order to learn how to add them.
A library is added in two steps
Adding headers path to the project
Adding .lib reference
In the first step, you must specify in the project where library headers are header. Usually, the path is specified in the project properties -> C++ -> Additional include directories, and them including files with relative paths.
In the second step you must specify in properties->linker the path where libraries (.lib) are located and the name of the library. With this Visual Studio is able to link the project properly.
go to project add existing item you must then select from the browse screen the .lib file you wish to add. and BINGO it is there!
best wishes
david

Build QtDropbox in C++ (Cannot find QLocale)

I am trying to build QtDropbox to use in a project of my own in visual studio. QtDropbox uses Qt of course and I included it into the project (as you can see on the image).
My problem is that it cannot find #include <QLocale>. So what dependency did I forgot?
In order to let your compiler find the mentioned include file you have to extend the list of Include Directories in your Visual Studio project's configuration. The mentioned file can be found in QtCore sub directory of Qt include files, so you simply need to add C:\Qt\5.4\msvc2013_64\include\QtCore path to the list too.

Visual studio 2008 Qt Project configuration

I am trying to configure my dll project so that I can access QtCore4.dll and QtGui4.dll functions.
In my project properties under c/c++, Additional Include Directories I have added ...\Qt\4.6.0;
project properties under Linker Additional library directories I have added Qt\4.6.0\lib
Right, so what #include do I need to put in my header files so that I can get the functionality?
Before I was using dependencies and using the includes and but now I have removed the dependencies I am getting a 'cannot open file: 'QtCore/qcoreapplication.h': no such file or directory error.
This project is making me feel like a moron.
Thanks.
Your additional Include directory should be ..\qt\4.6.0\include. If you use qmake or the VS plugin all this is done automatically.
Save yourself time and hassle, get the plugin: http://qt.nokia.com/downloads