QT: normal VS project file to build? - qt

I'm using QT (4.7.3) and I'd like to make normal VS solution/project files, build it, and step through the code with debugger to learn the code while reading tutorial...
Instead I have that yet another make qmake which supposed to be able to generate vs solution/project files but it seems that all it generates is some junk empty project files.
Here's what I did (from QT command promt):
cd c:\qt\4.7.3\examples\tutorial
qmake -t vcsubdirs
qmake -t vcapp
qmake -tp vc
but all of them generate random junk or errors...
I assume that I can also generate such solution for entire QT (from c:\qt\4.7.3) to build it from source...
What's the proper way to do it? It has tight integration with VS (designer, add-in etc) it just doesn't make sense that there is no normal solutions/project files there.
Did I do something wrong, or VS is kind of unsupported build platform? :)

Except for a few modes, like -project, qmake expects a valid project file to exist before you run those options. You'll also want to make sure that you're using a QMAKESPEC that corresponds to one of the MSVC versions. This SO post has some good details. To summarize:
Create your project file
Set your QMAKESPEC
Generate the solution file from the project file
That might look something like this:
$ qmake -project
$ set QMAKESPEC=win32-msvc2008
$ qmake -tp vc
qmake -project will regenerate the project file, so don't do that if you have modified your project file at all. The qtnode website also has some good information on using Qt4 with visual studio.

Related

Compiling an rcc file is skipped with cmake --build, but works with make. What could be the reason for this?

I have a larger project in which some *.qrc files are used and compiled using Qt's RCC. The project is configured via CMake as a Unix Makefile project.
When I build the program via make everything works without problems, but when I build via Cmake --build the corresponding files are not compiled. Unfortunately, CMake does not produce any output describing the problem (-verbose option is set). Does anyone have an idea what this could be? Could it be path variables? If so, how can I set them for the build process? What is the best way to debug such a problem?
To add the target I'm using qt5_add_binary_resources
The platform I am using is macOS.

QMake: copy files and folder from source directory to build directory

This is my first time using QMake on my QT as I mostly use CMake as I am really used to it. In Cmake I use add_custom_command() to perform task post build.
How can I do similar things in qmake?
My initial check I know it is something related to QMAKE_POST_LINK
but how do I specify it is for the build directory? (which as setup/created by QT Creator during build)
also by basic googling, i only found for unix{} and win32{} whats for mac?

Forcing specific version of QT in .pro file

I'm searching for a way to force a specific version of QT in a .pro file. To be more specific, I'd like to force qmake to use only QT 5.x version with my project instead of QT 4.x and QT 5.x
Is there a way to do so?
PS: I'm not asking for a way to stop/halt the compile process (aka check QT version, and if lower than 5.x just throw qFatal/equivalent). I'm looking for a way to actually choose which version to use while generating the Makefile with qmake
You can throw a error if a user is running qmake with a version you do not want him to use. ex:
lessThan(QT_MAJOR_VERSION, 5): error("requires Qt 5")
I really doubt you can do this. qmake is a part of framework and goes together with libraries. When you say Qt of specific verion you mean only libraries, but it is not correct.
To use specific version of Qt, you actially need to run different version of qmake. If you are using QtCreator - you should select it in project's options, if not - type absolute path to file qmake. You can find out, which version of Qt qmake uses, you can type qmake --version.
As Amartel wrote in his answer, you should point to the correct qmake version (check it by typing qmake --version in the console)
It might be that your project has been generated using the wrong qmake executable and some files are not removed even if you issue a nmake clean or make clean.
Check that there are no Makefile in the source tree after the clean (these files will typically contain the path to the qt version to use, and if not regenerated correctly will point to the wrong Qt version).

Build script for Visual Studio and Qt projects

I have an C++ application, which consists of several VS2010 projects and two Qt Creator projects (for the GUI).
I would like to have a build script, which builds all the projects at once. So what would be the best tool for the job?
Personally, I would change all projects to Qt projects and assemble them using the SUBDIRS template for .pro files.
You could then either run qmake on the top-level .pro file or do
qmake -tp vc -recursive
to create a VS solution and .vcproj files.
If that is not an option, you could just write a batch script which compiles them all. For VS 2008 I had batch scripts like this (File existence checks, error code handling etc omitted):
"%VS90COMNTOOLS%vsvars32.bat"
cd GUI
qmake GUI.pro
cd ..\Core
call vcbuild core.sln "Release|Win32"
The first is needed so vcbuild and nmake etc are known. It could be VS100COMNTOOLS or something like that for VS 2010, you may check your environment variables for that. Or maybe it's not even needed anymore.

Compiling Qt project in a directory outside of the install directory

I've been working on a project using OpenCV for a while, and am ready to upgrade my user interface from using cvWaitKey() to get key presses and emulating buttons with trackbars. Ha. So I've decided to use Qt.
I'd like to continue developing in the same directory I've been using, which is, of course, outside of the Qt install directory, C:\Qt\2010.05\qt. Using the "Qt Command Prompt", I'm able to compile the Hello Notepad example in directories both in and out of C:\Qt\2010.05\qt, namely C:\Qt\2010.05\qt\abc and C:\Qt\2010.05\abc.
However, while compiling under C:\ ... \qt produces executables in both the debug and release directories, compiling outside of it only produces the debug executable, along with a .o file (object code?). I did some comparisons using WinMerge, and found that the following lines (among others) differ in the two makefiles (generated using qmake -project and then qmake):
Inside qt\
first: all
install: debug-install release-install
uninstall: debug-uninstall release-uninstall
Outside qt\
first: debug
install: debug-install
uninstall: debug-uninstall
That's clearly the problem (the .pro files generated by qmake -project differ only in timestamp). I'm sure there's an easy answer out there to what's causing this... I hope there's an easy answer to how I can work around it. Also, I intend to use QtCreator some; hopefully the solution is the same for the IDE as the Command-Line compiler.
Thanks!
Nolan
p.s.: I don't think this is the same issue: Qmake does not support build directories below the source directory ...in any case, I'm not sure I understand the answer.
You should be able to add
CONFIG += release
to your .pro file, to build for release target. There's also
CONFIG += debug_and_release
iirc.
QtCreator has a GUI element for toggling between build targets, you might try opening the .pro with that application if you find you need to switch back and forth often.

Resources