How to create empty Qt project in visual studio 2010 - c++

Using visual studio C++ 2010 Ult.
I have compiled and instaled Qt libraries and visual studio add-in is installed into VC++ so I'm basicaly able to build Qt applications using Qt templates ofered from VS add-in.
I'm also able to include Qt headers and all works just fine...
installation has been done using VSC++ command promt, full build using
configure and nmake then.
QTDIR and PATH are properly seted up.
Qt libs are installed into:
(QTDIR) C:\Users\Admin\Documents\Libraries\Qt
(PATH) C:\Users\Admin\Documents\Libraries\Qt\bin
BIG BUT:
when crating new empty(or other non Qt template) project I can't include any Qt header so my question is how to enable this.
I want to set this so I can in all my future projects simply write:
#include <Qapplication>
#include <Qlabel> //etc...
thanks alot.

Maybe you can use the user properties for that? Set up the include and library paths there, then you should have Qt available for all projects.
See here: http://blogs.msdn.com/b/vsproject/archive/2009/07/07/vc-directories.aspx

For some reason VS can't find Qt headers. I think the only possibility is that you have not specified Qt include paths in the project (not for VS, just for a project). VS add-in always specifies these paths according to the user settings. The basic ones are ($(QTDIR)\include), $(QTDIR)\include\QtCore and $(QTDIR)\include\QtGui. The last one is necessary only when creating non-console GUI applications.

Related

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

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.

Visual Studio 2015 Ignores project specific includes

I am attempting to create a fresh VC++ project in Visual Studio 2015, in which I will be using the following libraries:
SDL2
GLEW
GLM
As I have done many times before, I have set the project up as follows:
Create empty project and add main.cpp with usual minimal main
function and build.
Add folder to solution directory (called lib), add copy the desired libraries to the folder.
In project properties, under all configurations, I navigate to VC++ directories, and enter the path for each library under includes, and library directories.
Under Linker>Input, I add the .lib files I will be using.
Finally, I copy the .dll files into debug/release folders in the solution directory.
At this stage, I should be able to type #include <sdl2.h>, or #include <gl\glew.h>, however, the headers cannot be found.
I have double checked all the filenames and paths, and all are correct. It's possible I may have missed something, but I've run through a few setup tutorials and checked a few old projects and everything seems fine.
Has anyone else heard of this, and if so, did you find a solution?
As it turned out, I had to reinstall visual studio. I had previously installed 2017 before 2015, so installed them in chronological order. I don't know that if that made a difference, but everything works fine now.

Why can't I find <QTcpServer>?

My VS2010 can only #include <Qt/qtcpserver.h> but can't #include <QTcpServer>.
Qt assistant suggested <QTcpServer> be included to apply TCP server but it seems this header cannot be found by my VS2010, but it can find <Qt/qtcpserver.h> and these two headers seems to be the same.
Are they the same and why can't I find <QTcpServer> ?
PS:
I'm currently using Qt4 plugin with VS2010.
Here's a snapshot of my VS project files:
No .pro file there.
You need to have
QT += network
in your .pro file to get the Qt networking headers and library correctly set up for your project.
For the Qt Visual Studio Add-in, look at the second tab of the project settings dialog box.
In your Qt project settings, add the network module. A guide with pictures:
http://doc.qt.digia.com/vs-add-in/vs-addin-managing-projects.html

Using Qt with Visual Studio without add-in

I recently started using Qt library and I've got a question.
Is this possible to use Qt with Visual Studio without special add-in?
I want to just design the UI using qt designer and do the rest in VS Express.
How do I do that?
Thanks.
Yes you can, if you would prefer not to use the QtVSAddin it is very easy to use Qt with VS Express without the VS add-in and without having to do any of the uic or moc steps manually. Let QMake (installed with Qt but not part of the QtVSAddin) create your VS project file and do all your project setup in a qmake project file. Whenever you make a change like adding/removing a form or source, modify the qmake project file and regenerate the VS project. Don't modify the VS project file at all, treat it only as a temporary item. QMake will add the rules automatically to the VS project file to rerun uic and moc, you don't need to do anything if you're just modifying source code or forms.
For configuration management purposes I find this a much cleaner approach to use this workflow as you treat the VS project file as only a temporary item (they tend to diff badly and are a pain to maintain in version control).
A couple snippets to help you out:
In your qmake project file ensure you add the following line into it so that VS project files are generated when running on Windows (qmake defaults to generating a makefile).
your_qmake_proj.pro
win32: TEMPLATE = vcapp
Additionally, it's convenient to have a batch file to rerun qmake so you don't have to bring up a command prompt and set environment up (or change directory to your project in a command prompt that already has the environment setup). If you haven't set the various Qt environment variables with Windows (or prefer not to) make sure to add them to your batch file.
makevcproj.bat
set QTDIR=C:\Qt\x.y.z
set PATH=%PATH%;%QTDIR%\bin
set QMAKESPEC=win32-msvcXXXX
qmake your_qmake_proj.pro
pause
CMake is also an answer and it does work with express versions of Visual Studio. I mean if you use the Qt support in CMake you can develop Qt projects in Visual Studio (like I have done for years) without the Qt Addon. I install the addon just for the debug expansion that comes in the same package.
It is certainly possible, but without the add-in you will need to UI and MOC the needed files either before you compile the rest within VS, or through pre-compile scripting.
Specifically:
uic generates the headers from .ui files.
and
moc generates the additional implementation files for classes that has Qt macros in it.
The add-in helps you call these smoothly on the required files before compiling the rest.
It's is possible if you create the UI in QtCreator and manually setup VS in a way that generate the UI and MOC files.
But it's too much work and you can use QtCreator which is an amazing light IDE.

What to do next after building wxWidgets successfully : Visual Studio 2010

I have downloaded c++ open source application which was created using under Linux IDE/Editor (or maybe something NOT Windows) and its no longer supported.
This time I want to edit and recompile it using VS 2010.
Error(s) left (mostly prefixed with "wx") such as:
"wxString is undefined"
"wxStaticText expected a type specifier"
etc... makes me think that this is all about wxWidgets.
After successfully building wxWidgets, what to do next to integrate it to the actual c++ program for me to be able to edit and compile using VS 2010?
I use BorlandC++ last 2 years ago but not familiar with GUI packages.
The first step is to tell the compiler where to look for the wxWidgets include files.
So, you need to find out where these files are, which depends on where you installed and built wxWidgets.
On my system, this is C:\Program Files (x86)\wxWidgets-2.8.12
I consider the best way is to, instead of hard-coding the path in every project, create an environment variable WXROOT to store the path to your wxWidgets folder.
Control Panel | System | Advanced | Environment variables
Now you have to tell the compiler about this
Visual Studio | Project | Properties | C/C++ | Additional Include Directories
What you add here depends on what kind of build you are doing. If you are doing a unicode release build, then this will be a good start
"$(WXROOT)\lib\vc_lib\mswu";"$(WXROOT)\include"
Now you should have fixed your compiler errors.
Next you will get some linker errors ....
Maybe the errors are caused because you are using wxwidget 2.8 which is unsupported in VS 2010.
Try building wxwidgets 2.9 or use VS 2008. I had no problem building wxwidgets 2.9 on VS 2010.
Wxwidgets site home says "While this is still officially a development release because some API details are still not frozen, we believe that 2.9.3 can be used in production environment".
About what to do after successfully build it, take a look at this http://wiki.wxwidgets.org/Microsoft_Visual_C%2B%2B_Guide
You may want to use the tutorial of the section "Creating a new project from a sample" 'cause creating a project by hand is a little bit complicated as wxwidgets requires some extra configuration and not just to set and include and libs dir as most of the libs does.
Here is a video which shows how to start with Visual Studio.
Also you can take a look at samples directory and create your own project based on configuration of projects from that directory.
May be I am little bit late , But this will help newcomers to wxwidgets.
First of all Goto Wxwidgets directory(to download path) in my case it is "C:\Users\WxWidgets_all".
Now in that folder goto build directory.Now open Visual Studio Command prompt. If you have already installed Visual Studio then you can easily find it through start menu.
Now in command prompt go upto <Path to your wxWidgets>/build/msw/ . Now run Following Commands.
nmake /f makefile.vc--For Static Library and Debug Version
nmake /f makefile.vc SHARED=1--For SHARED Library and Debug Version
nmake /f makefile.vc BUILD=release--For SHARED Library and Release Version
After completing it , you will have dll or lib in "<path to wxwidgets>\lib\" depending on option provided in above commands.
Now include all files related to wxwidgets in your project.Mainly two paths are required to include "<path to wxwidgets>\inlcude\" and "<path to wxwidgets>\lib\vc_<lib\dll>".
After that link your wxwidgets generated library to your project.To do this inlcude "<path to wxwidgets>\lib\vc_<lib\dll>" to your project property in library section.
Now add below preprocessors to your project.
_WINDOWS
NDEBUG(For Release)
_DEBUG(For Debug)
_CRT_SECURE_NO_DEPRECATE=1
_CRT_NON_CONFORMING_SWPRINTFS=1
_SCL_SECURE_NO_WARNINGS=1
__WXMSW__
_UNICODE
After that add following library to your project from "<path to wxwidgets>\lib\vc_<lib\dll>"
wxbase30u_net
wxmsw30u_core
wxbase30u
wxtiff
wxjpeg
wxpng
wxzlib
wxregexu
wxexpat
wxmsw30u_adv
Based on your compiled options , library name can be little bit different.
I think I have covered all the steps to run wxWidgets.
Even if you got errors , You can check minimal project in "<path to wxwidgets>\samples"
directory. Try to run that project , and even if you got error then your wxwidgets is not built properly.
Hope this will help.