Qt, Qmake and Visual Studio 2013 - c++

I'm currenlty working on a portable project. To make it easier to compile on linux and windows, I'd like to use a .pro file which will generate a Makefile on linux and a visual studio project on windows.
But, I'm facing a problem on a very basic example.
Here is my .pro file:
TEMPLATE = app
TARGET = client
CONFIG += debug
SOURCES += src/main.cpp
My main.cpp only contains an empty main:
int main(void) { return 0; }
Then, I just open my visual studio console, cd in my project folder and run qmake.exe -spec win32-msvc2013 -tp vc.
This generates the expected vcxproj file, that I can open with visual studio.
The program compiles well with visual, but I got a fail during the execution: Qt5Cored.dll missing.
I've verified:
In the project properties, Qt lib directory has been added to the libraries directories
Qt5Cored.dll exists (and is located in the Qt lib directory)
I'm compiling and executing in debug environment
Additionnal information:
Qt is well installed
When I create a Qt5 project via visual studio, it works well (but this is not what I want).
When I manually import the .pro file using the Qt add-in, the vcxproj generated works well (no error during the execution): what's the difference? why the qmake doesn't work, but manual import does? Have I missed something to make the qmake work?

As someone has said in the comments of my question, the solution is pretty simple: I just needed to add the Qt bin path to the Windows PATH environment variable.
Problem solved :)

Related

Generating Qt pro files from sln file

I like to make Qt applications in Visual Studio. But sometimes, there is a need to continue development in Linux space, where Visual Studio is not available. Therefore, there's a need to write down project files manually.
Is it possible to generate .pro files and makefiles from configurated .sln file?
I don't use Microsoft Visual Studio so I never had to deal with .sln files.
But actually, to generate your Qt environment from the command line in linux, you don't need the .sln file.You just have to do as follows:
Create your project directory, let's call it MyQtProject
Copy inside your sources files (.h, .cpp)
Then cd MyQtProject and run qmake -project : It will read your directory and create your .pro file (adding your headers and sources files, ...).
You can edit the generated MyQtProject.pro file to add some specific instructions (for exampleQT += widgets)
Then you just have to run qmake MyQtProject.pro to generate the Makefile.
Finally run make to compile.
Of course, you can create a build directory inside MyQtProject and run qmake ../MyQtProject.pro and make from inside it in order to not pollute your project folder with the moc files and the cmake related files.
I hope it can help you and solve your problem.

qmake: how to remove the dependency of absolute paths?

Qt Creator + VC19 (MSVC2015) + WinSDK8.1
No Qt itself used. Just console application std+boost+catch+easyloggingpp
VC\bin and WinSDK\bin both are in a system path variable.
all includes and lib paths configured in a pro file.
I need to move them out from project file to build this project on various machines (all windows but different locations of the used libraries).
I think that cl.exe can read this from LIB and INCLUDE env variables, but if I do this (set headers and libraries paths from bat file or in a project settings in QT Creator) it doesn't work, QtC reports me that can't find some headers.
Could you clarify for me:
Should Qt Creator read LIB and INCLUDE variables for the build and parsing? What is right steps to make it working?
If Qt Creator can't read the env variables , then what is right way to remove the dependency of absolute paths in project build with qmake?
You obviously have Visual Studio compiler and other standard library paths hardcoded as absolute in your project file?
All the Visual Studio or other compiler settings e.g. tool chain location are normally read by Qt Creator from compiler kit. Adding Compilers article clarifies on that. That is the first thing to configure as long as your system has Visual Studio installed. Having configured compiler kit you will be able to add one to your current project build: Configuring Projects article.
And in case if you build from command line with qmake and jom: your build script may execute the Visual Studio standard environment batch script file like:
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\VcVarsAll.bat" amd64
Mind the target bitness (32/64) and actual location of your Visual Studio. There is MSDN article for that: Setting the Path and Environment Variables for Command-Line Builds.

How to make .exe file in Qt Creator

I was working on Qt Creator compiler to make a simple text editor. I did that but now want to make an .exe file of that project, but I don't know how to make an .exe file in Qt Creator compiler. Can anyone help?
There is a tool that adds the .dlls automatically on windows.
In the command prompt navigate to your qt bin directory. It should look something like this: ...\Qt\5.9.1\msvc2017_64\bin\ (I'm using visual studio).
Run windeployqt.exe in the command prompt with your project location as the argument like this:
windeployqt.exe C:\project_folder\my_project.exe
Now my_project.exe will have the .dlls in the same directory and will execute.
The executable is generated by the compiler when you build your application. To know where the executable is stored, look into
Projects (CTRL+5) -> Build settings -> General -> Build directory
This is where Qt creator will put the .exe it generates if you have shadow build enabled.
If shadow build is disabled, the executable will be stored inside the project folder itself.
From:
How to create executable file for a Qt Application?
Basically you have to look for MinGW subfolder deep into Qt tree, where Qt utilities reside, and copy needed dll's.
These are the steps I follow, based upon Qt 4.7.4, for packaging the application with correct shared libraries.
Let's say you've installed Qt under c:\qtsdk.
Open your project, and compile it in release mode.
Go to this directory: C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin -- it contains all shared libraries. Debug libraries end with a "d" -- frex, QtCore.dll is release version, while QtCoreD.dll is debug version.
Copy at least these files into your release directory (where your .exe lies):
mingwm10.dll
libgcc_s_dw2-1.dll
QtCore4.dll
QtGui4.dll
I just built, tested and deployed a dummy project this way.
I had the same problem so I used the suggested above answer:
"
There is a tool that adds the .dlls automatically on windows.
In the command prompt navigate to your qt bin directory. It should look something like this: ...\Qt\5.9.1\msvc2017_64\bin\ (I'm using visual studio).
Run windeployqt.exe in the command prompt with your project location as the argument like this:
windeployqt.exe C:\project_folder\my_project.exe
Now my_project.exe will have the .dlls in the same directory and will execute.
"
but there somethings that I did so this might help:
there is already an executable version of your app in the debug file of your project if you can't find it try to enter properties in Qt creator an track down the file. while you are at it in properties you can also see whether your app is using msvc2017_64 like in the previous answer or other compilers.
Take that file to the same path you write in the command line here: windeployqt.exe C:\project_folder\my_project.exe.
when your try to open the executable file it will till it needs some dlls files that you can find in this path .\Qt\5.9.1\msvc2017_64\bin copy and paste them in the location of the exe file
Steps to make an exe file from your qt project
In Build Settings make sure Edit build configuration is Release.
In Build Settings uncheck Shadow build(this will make sure that the release folder is inside of your project directory instead of outside of your project directory).
Build and run you project(This will create a release directory inside of yours project folder).
Copy *.dll and *.exe file from C:\Qt\6.3.2\mingw_64\bin to the release folder (where your projects exe file is there).
Copy all folders from C:\Qt\6.3.2\mingw_64\plugins to the release folder.
Now you can launch the exe file inside of your release folder corresponding to your project.

QT yaml-cpp Windows

i am new on programming in windows and in QT.
I started a QT project and want include yaml-cpp 0.30
Now i have different problems. First i wanted to build the lib with cmake and Visualstudio but i am not sure if i did this right.
I start Cmake and build with VS2010 compiler. Then i load the file
build\CMakeFiles\2.8.11.2\CompilerIdCXX\CompilerCXX.vcxproj in VS 2010 but i cant build this or dont know how.
And how i integrate this build lib inside QTCreator?
Or i have the possibility to build all inside QTCREATOR?
thanks for your help
CMake will build a Visual Studio solution (a .sln file); you don't need to go into the CMakeFiles directory to find it. There should be a solution file in the top build directory.

Build C++ Projects with Makefile using Visual Studio 2008

I downloaded cpptest from internet, and I want to build it using Visual Studio 2008.
The problem is that instead of .sln and vcproj file, Makefile.am is distributed, and I believe that all the all the necessary included file is included in the Makefile.am.
How to use Makefile.am to generate VS project files? I tried to use Cmake, but there is no CMakeList in the distribution.
Edit: Thanks to all the answers! There is a sln file distributed after all. But I am still interested to know the answer to my original question.
the visual studio project files for cpptest are in the win directory, not in the src directory where the makefile is..
edit
makefiles are meant to be used with GNU make. If you want that on windows, you can look at Mingw, GnuWin32 or Cygwin. But they also require gcc for compiling, so you won't really be using VS.
However, for most projects that do not have external dependencies it's no big deal if you do not have the VS project file: after all a makefile is just a list of the source files and some compilation options. To successfully build projects like cpptest, you could just create an emtpy VS project, add all source files to it, set output type to executable, build it and you're done. Eventually you can tune optimization options, but for the rest the default options will just do fine.
Go to win\VisualStudio.NET and you will find a VS solution file.
I just downloaded the archive and found the .sln file. It is under: /win/VisualStudio.NET. You can open that with VS2008 and update it, it should work.