qmake TEMPLATE = subdirs visual studio project generation - visual-studio

in my project I'm using in my "main" .pro file TEMPLATE = subdirs that includes other sub-projects(2 additional libraries + target executable). As an outcome I would like to have an application that is linked against those 2 libraries. Based on my pro files structure I would like to generate visual studio 2008 or 2010 project file as some people prefer visual studio than Qt Creator as their IDE. What I have tried was:
qmake -t vcapp -spec win32-msvc2008 main.pro
but it gives some kind of an empty visual project file. If I repeat the same step for all my subdir project everything is fine. Only creating "the main one" that should have sub-projects in dependencies is not working correctly. I'm using qmake that comes with qt 4.7.3 release on Windows.

Use this:
qmake main.pro -tp vc -r

Related

Visual Studio 2017 - How to create a project from the source using CMake?

I have a pretty large software library using CMake to be compiled. We use Linux mostly, but now a new colleague wants to use Visual Studio.
Is there any way to create a new VS 2017 project from the existing source codes with CMake structure?
I know, it's possible to do it with CLion, but I have no idea about VS, as I have a very little experience with it.
Other questions seem to focus on creating an empty project, which will use CMake, but not on creating a project from already existing source files.
Creating a cmake project with visual studio
Creating a project with visual studio 2017
I'm not sure why you asked for details but...
Assuming you are using cmake 3.13 then you can do the following in a command shell:
cmake -G "Visual Studio 15 2017" -S path_to_source -B path_to_build
This will then create a solution file. Actually it creates a solution file for every project() command that is issued in CMakeLists.txt.
You can then open the solution file in Visual Studio, and build the project as usual.
You don't even need to do this in the Visual Studio GUI. After creating the initial project you can also issue the command:
cmake --build path_to_build
Which will kick off the build at the command line.
Now if your CMakeLists.txt in path_to_source is using Linux specific libraries or gcc specific compiler settings then the CMakeLists.txt will have to get updated to the Windows equivalent.
The alternative is to start Visual Studio and then use File->Open->CMake and open the CMakeLists.txt file in path_to_source. It'll then start to generate the project. But I prefer using the command line method.

Generate Visual Studio Project File to build a library with qmake syntax and where to find the project file?

I have an old script to create Visual Studio Project Files to build libraries. The syntax is
cd Kernel
cd core
qmake -t vclib
cd ccMigration
qmake -t vclib
cd ..
and so on for all of the different directories.
I understand why we use qmake and vclib, but what I am not sure is what is the use of -t in this line:
qmake -t vclib
Looking at this : http://doc.qt.io/archives/qt-5.5/qmake-platform-notes.html it says:
Creating Visual Studio Project Files This section describes how to
import an existing qmake project into Visual Studio. qmake is able to
take a project file and create a Visual Studio project that contains
all the necessary information required by the development environment.
This is achieved by setting the qmake project template to either vcapp
(for application projects) or vclib (for library projects).
This can also be set using a command line option, for example:
qmake -tp vc
Why do they use -tp and is the old script syntax correct by using -t?
After I run the script it takes about 1/2 seconds and where can I find the project files for Visual Studio?
Finally, When I open the project files how can I build a library using Visual Studio? Can someone point me to a place where I can read some material?
Thank you for all the help!
Edit: I ran the script and it created .vcproj files in the directories that qmake was run. Example: In folder Kernel -> core it created ccCore.vcproj project file. When I open the file in Visual Studio 2017 it wanted me to perform a One-way upgrade that will automatically make functional changes to the project in order to open it. Is this okay?

QT QSqlDatabase, Add to Visual Studio Project

I am looking for direction on how I might include the QT ODBC source in my Visual Studio 2010 executable. My project requires a modification of the SQLResult class and prefer to include the source in my application instead of linking in the object configure -static.
FWIW: I am a registered Enterprise user with a valid license.
Many thanks!
This is what I did... I do hope that these steps are useful to others.
My Environment: Visual Studio 2010 Ultimate
Download build from QT
Extract Build to directory...
C:\Qt\qt-everywhere-enterprise-src-5.2.1\
For each (x86/x64) platforms:
Program \Visual Studio Tools \ command prompt
create directory for QT platform
In my case: c:\qt\x86 and c:\qt\x64
Set the environment path to QT base:
QTDIR=C:\Qt\x86\qt-everywhere-enterprise-src-5.2.1\qtbase
At the command prompt:
set PATH=%CD%\qtbase\bin;%PATH%
Include any modules: Note -static
configure -static -prefix %CD%\qtbase -qt-sql-odbc -opengl desktop
nmake
For sql plug in:
cd src/sql
Create a VSProj file and include in your project.
qmake -tp vc
In Visual Studio ensure the VS Addin is installed on the system. At the VS Menu Qt5 menu. Selection options. Create a build
to associate the VS addin to.
c/C++ hive
General Additional Include:
.\GeneratedFiles;.;$(QTDIR)\include;
.\GeneratedFiles\$(ConfigurationName);
$(QTDIR)\include\QtCore;
$(QTDIR)\include\QtGui;
$(QTDIR)\include\QtSql;
$(QTDIR)\include\QtWidgets;
$(QTDIR)\include\QtNetwork;
$(QTDIR)\include\QtConcurrent;
.\header;
$(QTDIR)\plugins\platforms;
%(AdditionalIncludeDirectories)
Ensure all libraries are referenced in VS Project properties\linker\input\additional dependencies
Linker \ General \ Additional Library Directories
$(QTDIR)\lib;$(QTDIR)\plugins\platforms;%(AdditionalLibraryDirectories)

Cmake not finding Visual Studios 2012 in Generators list

I'm trying to run through the Firebreath tutorial, but I cannot get Cmake to work. Cmake does not register any version of Visual Studios under the Generators list. This is the list when running cmake --help:
Generators
The following generators are available on this platform:
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files (experimental).
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles
= Generates Eclipse CDT 4.0 project files.
KDevelop3 = Generates KDevelop 3 project files.
KDevelop3 - Unix Makefiles = Generates KDevelop 3 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
I have re-installed CMake, installing Visual Studios 2010 and 2012 (Express and Professional editions), and even uninstalled and re-installed .NET 4.0 to 4.5 (from here). It works fine on my personal computer, as I got it running on the first go. However, my work laptop is just not registering Visual Studios.
I'm running it both on Windows 7 Enterprise SP1. Any help is appreciated.
Here is the exact error I am getting:
C:\code\tutorial2\TutorialTestPlugin>firebreath\prep2012.cmd . build
A subdirectory or file build already exists.
Using projects in: "C:\code\tutorial2\TutorialTestPlugin"
Generating build files in: "C:\code\tutorial2\TutorialTestPlugin\build"
NOTE: The build files in "C:\code\tutorial2\TutorialTestPlugin\build" should *NE
VER* be modified directly.
When needed, make project changes in cmake files and re-run this script.
Project-specific cmake files are found in [plugin dir]\CMakeLists.txt and
[plugin dir]\Win\projectDef.cmake.
Note that parameters for cmake should be enclosed in double quotes, e.g. "-DVERB
OSE=1"
CMAKE parameters:
C:\code\tutorial2\TutorialTestPlugin\build>cmake -G "Visual Studio 11" -DFB_PROJ
ECTS_DIR="C:\code\tutorial2\TutorialTestPlugin" "C:\code\tutorial2\TutorialTest
Plugin\firebreath"
CMake Error: Could not create named generator Visual Studio 11
cygwin warning:
MS-DOS style path detected: C:\code\tutorial2\TutorialTestPlugin\firebreath
Preferred POSIX equivalent is: /cygdrive/c/code/tutorial2/TutorialTestPlugin/f
irebreath
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
The problem is you are using the cmake that is included in cygwin instead of the windows version of cmake. It appears that the current cygwin version is compiled without the generators for Visual Studio while the windows version has these.
In your case a simple way to get windows to use the windows version of cmake is to uninstall the cygwin cmake since it does not appear that you need that anyways.
An alternate method would have been adjusting your system path so that c:\cygwin\bin is after C:\Program Files (x86)\CMake 2.8\bin.

Compiling a simple Qt "Hello World!" application within Visual Studio 2010 Express?

I'm trying to build a basic Qt "Hello, world!" application inside Visual Studio.
I got the moc step to work (I think), but now I am at a loss as to how to fix this linker error:
1>moc_mainwindow.obj : error LNK2001: unresolved external symbol "public:
static struct QMetaObject const QMainWindow::staticMetaObject"
(?staticMetaObject#QMainWindow##2UQMetaObject##B)
I've done a lot of searching but I am at a loss.
Here are my include directories:
i:\Qt\4.6.3\include\QtCore;
i:\Qt\4.6.3\include\QtGui;
i:\Qt\4.6.3\include;
i:\Qt\4.6.3\include\ActiveQt;
reease;
.;
i:\Qt\4.6.3\mkspecs\win32-msvc2008
Here are the libraries I am linking against:
i:\Qt\4.6.3\lib\QtGui4.lib;
i:\Qt\4.6.3\lib\QtCore4.lib;
gdi32.lib;
comdlg32.lib;
oleaut32.lib;
imm32.lib;
winmm.lib;
winspool.lib;
ws2_32.lib;
ole32.lib;
user32.lib;
advapi32.lib;
libpng.lib;
msimg32.lib;
shell32.lib;
kernel32.lib;
uuid.lib;
Does anyone have any ideas?
qmake will generate the moc voodoo from the header file in .pro file. As you aren't using qmake, by the sound of it, but a native visual studio project, this is probably the cause of the problem.
If you use qmake to generate your visual studio project all your problems will go away and life will be sweet. Probably!
I am using the open 2010.05; obviously you want to substitute the correct path for your version.
set up the environment
start 2010 command environment from the start menu
-set include=%include%;C:\Qt\2010.05\qt\include
-set lib=%lib%;C:\Qt\2010.05\qt\lib
-set path=%path%;C:\Qt\2010.05\qt\bin
-set QMAKESPEC=win32-msvc2010
write code, create files etc
generate the initial pro and makefile and fire up VS
-qmake -tp vc
-qmake
you should now have a makefile - check that it works by running:
-nmake
now launch visual studio
-VCExpress.exe /useenv
-XXX.vcxproj can now be opened
If this doesn't work you may need to build qt at against visual studio. This is very straightforward - go to the qt directory (from within the visual studio express command window) and type:
configure.exe -platform win32-msvc2010 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast
You cannot install the Qt VS plugin on the Express edition of VC++. Assuming you got the moc to compile, you also need to make sure you're including the appropriate libraries (*.lib files) at link time. This goes under Project properties > Linker > Input > Additional Dependencies.
You will need qtcore4.lib at a minimum.
Also make sure the Qt library path is in your library search path. On my computer it's c:\qt\4.6.2\lib.
I was able to get QT to work with Visual C++ Express 2010 using http://rajorshi.net/blog/2009/01/using-qt-with-msvc-express-2008/ and http://portfolio.delinkx.com/files/Qt.pdf as guides. Just in case anyone still is having problems.
Have you create the visual studio project using qmake first? The problem seems to be the moc compilation. Do you have qt plug-in installed and the qt path in enviromental variables? Can you add you hello world code so I can have a look at it?
You need to add commands to generate QT metaclasses, then also include the generated files in your project as c++ code.
Generating the QT metaclasses:
First, add your QT bin path into the Executable Directory. (This is in Configuration Properties > VC++ Directories)
Add your Header files that contain Q_OBJECT macros to the project.
Multi-select your header files, then right click on a header file, click Properties.
Change "Item Type" from "C/C++ Header" to "Custom Build Tool".
Set Command line to this: moc.exe "%(FullPath)" > "$(ProjectDir)MetaObjects\moc_%(Filename).cpp"
Set Description to this: QT: Generate $(ProjectDir)MetaObjects\moc_%(Filename).cpp (optional)
Set Outputs to this: $(ProjectDir)MetaObjects\moc_%(Filename).cpp
Run Build just to make it generate the metaobject code
Add the generated C++ files from the Project Directory Metaobjects folder into your project

Resources