Simultaneous development in Visual Studio and Qt Creator - c++

I'm going to develop a bunch of projects with Qt that should compile both under Visual Studio with Qt integration (commercial) and Qt Creator with LGPL SDK. My primary IDE is VS but I've grown to like Qt Creator too. It would be nice to be able to work in both of them simultaneously. I need to do it in some extent anyway.
The most annoying problem is project management. Should I create .pro file first and then import it to VS? Or should I create VS project first and create .pro file by Qt integration utilities? What's the best way to do it?
I would like to hear your ideas on the subject.

I use the .pro files as a basis and create VS projects from them. Using scoping rules I can set options that are specific for the VC++ compiler or the MinGW compiler. I haven't encountered any VS option yet I couldn't specify in a .pro file. OK, make that one: trying to set the warning level to 4 (win32:QMAKE_CXXFLAGS_DEBUG += /W4) didn't work because /W3 was still present.
For adding new files to the project I sometimes just add them to the .pro files and setup the VS project again. That way I don't have to worry about keeping both in sync.
Using this approach makes it easy to do automatic builds under a variety of compilers (Microsoft, Intel, MinGW, 64bit cross compilers)

Do you mean Qt Designer or Qt Creator? Qt Designer is the form builder, Qt Creator is the IDE.
I would recommend delegating your project management to CMake. Qt Creator now has support for cmake. cmake generates you project files based on a simple set of description files. I now use cmake even if I am just using visual studio because it is much easier to manage common settings between related projects than updating loads of settings in different dialog boxes. It also is also a multi platform build and is very clever at discovering the build tools and libraries installed on the developer system and creating the appropriate build output, make files, and ide project files.

I am glad you were able to solve you current issue QT Creator is a great tool. As much I like QT Creator and dislike Visual Studio, if you need to work with other developers on windows skipping support for visual studio in the future may not be an option.
I have had good luck using CMake ( http://cmake.org/ ) to generate my project files. I am working on a Linux/windows project where the developers can use just about any IDE and compiler. Learning to use CMake is easy, learning to make good cmake scripts takes a little time though. However, QT Creator has the ability to create the CMake projects for you, and you can customize and learn just as much of the CMake build script language as you need to.
Like this I have worked with visual studio, Code::blocks, QT Creator, clang, gcc/mingw and the vc++ compiler.

My approach was to create the project in VC++ and then export it to pro. I then tweaked all the pro files by hand and I keep them in sync by hand.
It's better to start with VC++, because VC++ has many more options that Qt's pro files.
Once you start changing more advanced options you will want to sync by hand
Make sure that both toolchains output the files in the same directories, or you might encounter issues such as moc files in your project dir that are updated only by QtCreator, while VC++ only updates the ones in GenratedFiles which the compiler can't see due to the former.

I have dropped Visual Studio for C++ development. Now I use only Qt Creator. All the troubles with parallel ways just do not worth it.

Related

Can I use Qt visual studio tools for comercial projects?

I understand that I can work on closed source projects using Qt as long as I link dynamically the Qt libraries and don't include them in the release version of my app.
My question is, if I use Qt visual studio tools, would it compile it including the Qt libraries on my release? if so, how could I make use of Qt libraries in visual studio?
Also I guess another question would be, if I use the Qt IDE's like Qt Design studio can I compile my app so that it links the Qt framework dynamically?
This dialog in the installer has the answers to all your questions. So, with these limitations in this wizard, you can use the open source version of Qt in your project.
And yes, you can of course link against Qt dynamically either in qmake or cmake.
All these common and popular IDEs support cmake, like Visual Studio or QtCreator, so you should not worry about using Qt in these IDEs.

Building QT with Visual Studio

I know there have been a few questions before regarding this, but not too much up to date.
I am developing a project with Visual Studio 2015 express edition and I wish to add a GUI to my project via QT.
The latest version of QT (5.8.0) has a VS 2015 version, so I assume it is compiled using Visual Studio instead of MinGw.
Sorry if this is a very noob question. I have no experience with QT, but how do I then integrate my QT project into my VS project, do I build the GUI code first in QT?
If I will create a GUI using the .ui file in QT and then generate the source code for this, can I just copy the source code to my VS Project. I assume I have to configure the project file in VS as how will VS know where to find the dlls and header files for QT? Thanks in advance
You need the VS Tools for Qt. They work with >= Visual Studio 2013 Community Edition.
You can get them here and all information about how to use them.
Qt VS Tools integrate the Qt development tools into Microsoft Visual Studio 2013, and later. This enables developers to use the standard Windows development environment without having to worry about Qt-related build steps or tools.
The main features of Qt VS Tools are:
Wizards for creating new Qt projects and classes.
Automated build setup for the Meta-Object Compiler (moc), User Interface Compiler (uic), and Resource Compiler (rcc).
Import and export of Qt project files (.pro) and project include files (.pri).
*Automated conversion of a Qt VS Tools project to a qmake project, or the other way around.
Integrated Qt resource management.
Integrated Qt documentation.
Debugging extensions for Qt data types.

Integrating separate Qt and Visual studio 2008 projects together

I have a Qt project(.pro) which essentially uses Qt libraries and OpenGL and i need to integrate this project with an existing VS2008 project(.vcproj) which uses a 3rd party API on another system.
The VS project interfaces with a hardware(along with many other functions) through a serial port and i intend to use its event handler to trigger the actions in Qt( since a serial port cannot be opened by two programs simultaneously? )
I use Qt v4.8.1 with mingw complier. i did come across a VS plugin for Qt. but i'm not sure as to how the above task of integration can be done.
I'll be thankful if you can kindly shed some light on this.
My advice would be to completely integrate the source of the Qt project into the VS project. It's possible to compile Qt code in visual studio. Of course, this requires to configure your VS project to make it "qt-ready". In detail:
Integrate the source code of the qt project into the VS solution. This means, the header files, the cpp files and the ui files you might have.
You still need the Qt libraries on your system in order to compile QT source with visual studio. I recommend to install "qt-win-opensource-4.8.1-vs2008.exe". These are the special Qt 4.8.1 libaries for VS 2008 (pre-compiled). Can be found here: http://download.qt-project.org/archive/qt/4.8/4.8.1/
You have to tell visual studio how to "pre-compile" the Qt source with the installed Qt binaries. This can be down in two ways:
I. You can configure the project properties of your VS project. Unfortunatelly I have never used this way, so I don't know exactly how to do this.
II. You can use CMake to setup your VS project. CMake allows the simple integration of Qt libaries and compilers. Using CMake means to write a CMakeLists.txt, which generates the VS project for you. Here you can find a sample, explaining how to write a CMakeLists.txt with Qt support: http://www.cmake.org/Wiki/CMake/Tutorials/Qt
Also, the Qt plugin for visual studio you mentioned is optional. You do not need it to build a Qt project with visual studio, but it makes some issues easier, e.g. debugging or calling the Qt designer from visual studio.
Hope this helps,
Michael

Is it possible to use vs2010 c++ and use Qt for all platforms?

What i hear about Qt, is that it is providing an operating system independent layer.
To do well most tasks a coder normally does. To perform at best the code has to be c++
While there is also mono providing some translation to c++ and there Dot24 an android c# kernel.
Currently the things we do, cannt be done in mono, for hardware reasons.
So i am thinking of going back to pure C++ and QT instead of C#.
Now what i am wondered about
By itself c++ is a standard and should also be idenpendent for linux/windows/unix/microboards/Ce devices etc etc.
But if i would write using VS2010 c++ and QT would i still have advantage my code would run on a wide range of platforms ? . As visual studio, creates a windows based exe? Or should i use also another IDE to write truely independent c++ with Qt?
C++ is a compiled language, whatever IDE/compiler you'll use it will produce executables for a certain platform. But the point of Qt is that, as far as you avoid platform-specific code, your sources can be recompiled on the various platforms, generating a different executable for each supported platform. So, using VC++ is not a limitation as far as sources are concerned.
The limitation comes instead from the build system: Visual C++ uses its own format for project files, which is not compatible with makefiles & co. So, if you started your project as a VC++ project, you would have to re-create manually a Makefile or similar to compile on other platforms.
To avoid this kind of problems, Qt provides qmake, a tool that, provided a .pro file (roughly equivalent to a .vcproj), is able to generate build files for various platforms: .vcproj/.dsp on Windows, Makefile on Linux and OS X, XCode projects on OS X and probably others.
So the point is: you can use Visual Studio, but you should use Qt's build system to be able to port your application to other platforms without any fuss.
Also, you can consider using Qt Creator, which supports directly .pro files, has particularly good integration with the Qt features and works on Windows, Linux and OS X; on the downside, I noticed that the debugger in Visual Studio tends to be way better.
If you have cross-platform C++ code using Qt, you can edit and compile the Windows version using Visual C++ (the compiler that comes in Visual Studio).
Visual C++ still only creates Windows executables, though, so to actually build and run on other platforms, you'll have to get another compiler (but feed in the same source code).
One pain point will be with makefiles: visual Studio has its own project format and cannot process standard makefiles. Neither do other platforms use Visual Studio projects. Visual Studio does come with a tool called nmake which is similar to POSIX or GNU make, but still not compatible except for the most trivial features. And of course cl.exe uses different command-line switches than other compilers. So you'll end up maintaining one set of C++ files but two or more sets of makefiles.
Yes it is possible to develop Qt applications in Visual Studio that can be used on other platforms. For example for my work in medical imaging research, I develop all of my Qt based applications in Visual Studio 2010 with the visual studio project files generated using CMake and at times build some of these applications in linux under QtCreator or KDevelop using the same CMakeLists.txt to generate project files for for these IDEs. As long as I stay away from platform specific code the porting is not that difficult.
In order to develop qt apps qtcreator is the best ide, qtcreator available on linux and mac, so you can open your qt project and build on any platform easily.

Visual C++ 2010 and Qt (moc etc)

I'm using Visual Studio 2010 Ultimate and I know there's the Qt VS Add-In. However I've chosen to not use it as according to an announcement by Nokia they will not release any further versions of it. So now would be a good time to change work practises.
I'm looking for a way to automatically call moc.exe on class files that need to be moc'ed, and for the moc'ed files to be compiled as well. I'll probably do this for the resource/ui compilers as well.
Qt's plugin simply creates Visual Studio build rules files - these are 'normal' xml files and anything can use them.
There were a series of add-in VS macros before the visual studio plugin became available.
Add-in is mainly useful to import .pro files to VS projects, after that you do not really need the add-in (unless for making it easier to change between different Qt versions).
Just make sure to define QTDIR in a project property page (.vsprops) as UserMacro and have it exported to the environment, then you can use it for $(QTDIR)\bin\moc.exe against Qt header files in the custom build step, similarly for UIs.
<UserMacro
Name="QTDIR"
Value="C:\Qt\4.6.3"
PerformEnvironmentSet="true"
/>