Setting up Qt 5 with Visual Express C++ 2012 on Windows 7 32 Bit - c++

How do I exactly set up QT5 to be fully working?
I downloaded and installed:
Qt 5.2.1 for Windows 32-bit (VS 2012, 541 MB)
Visual Express C++ 2012
I ran the examples on QT Creator. They are all compiled and running fine. Simple hello.cpp also works okay
However, I can never understand why:
Running command prompt of QT or C++ native from VS will not let me do "make". qmake -project and qmake XXXX.pro is running fine. (Note: I can do compile well in QTCreator)
Subclassing cannot find its way to the folder. QTCreator complain LNK2019 and LNK1120
Could someone please list step by step on how to set these two software works seamlessly (QT5 and VS2012) from clean installation? I simply want to start coding gui with C++; nothing complex yet.
P.S. I could not find clear answer and guide regarding this matter. I can't register on QT site too (always say "no content to display" on registration page).
Anyway, thank you for the time, effort and attention.
Update: I have windows 8 at home, installed Qt5 and VS12. It works seamlessly. At work, the IT guy is stubborn to install windows 7.... Qt5 and VS12 in windows 7 is not the combo apparently. When compiling, it complains "where the hell is QDialog, QApplication, Q.... or whatever #include...?" I will try something else next week and will update you all.

Wow, what a mind blowing.
Here is the story in my Win7:
1. Installed VS2013, Qt does not like it. Then, I install VS2012. Still does not like it. Then, uninstall everything including deleting C:\Program Files\Microsoft VS 11.0 and 12.0.
2. I install VS2010 and QT for VS2010. Still not working.
Finally, uninstall and delete everything (including all folders in program files and c:\QT), I install VS2012 first then install QT for VS2012. It works....
Hope this help anyone who has problem in compiling during their first install in Win7.

Compiling a QT5 application in VS2012 can be really tricky depending on your current setup. Here's a summary of the most important guidelines to make it work like a charm:
First, it is required that your QT5 version is msvc2012. Otherwise,
it won't work. Make sure that a folder called msvc2012 exists.
Create a QT5 project file (.pro) that represents your current headers and
definitions. Make sure that the TEMPLATE config is set to vcapp.
Run >> qmake yourProject.pro in the command prompt. This should
generate a Visual Studio project (.vcxproj) file that can be openend
with Visual Studio 2012. Note: if there is more than one version of
VS installed on your system, qmake will more likely take a weird
decision and take the older one (qmake you're a bad kitty!). In this
case you must call the qmake from the VS command prompt directly.
Open the .vcxproj with Visual Studio 2012 and compile.
Any problem that may occur, for example compilation failure, is related to one of these steps being incorrectly done.
Useful references:
How to create a QMake project files, How to set environment variables

in vs2008 there is vsvars32.bat that sets up the variables to let you call make from basic cmd.exe. maybe something exists for Vs2012.
under windows systems its not make, it should be nmake

Related

Qt VS Tools: error reading VS project settings

I develop an application using Visual Studio 2015 + Qt VS Tools extension. For me it's first time I used Qt (version 5.14.1) in my project. Everything was working fine until something wrong happened.
I was asked to make release version of my application, it worked fine on Windows 10 and Windows 7 64-bit systems. Then I set the project configuration back to Debug x64 to continue my work. First strange thing I noticed - when I double-clicked on *.ui form files in my Solution Explorer, Visual Studio crashed and reloaded without any error, Qt Designer doesn't launch.
What I tried:
First I tried to open Qt Designer externally (from bin folder in Qt directory) and open my form - it worked.
I tried another project made in VS 2015 + Qt VS Tools Extension - same problem.
I tried to remove my Qt Version and re-add it. And here it comes: Error screenshot. It also occurs without using system enviroment variable $(QTDIR).
I reinstalled Qt to my PC (installed version 5.14.2 instead of 5.14.1), same error.
I reinstalled Visual Studio 2015, same error.
I tried to reset my Visual Studio settings and parameters to default, no results.
I installed Visual Studio 2019. The problem is still present.
UPD:
I cleared Visual Studio cache according to these instructions. It didn't work for me.
I removed every Visual C++ Redistributables from my PC and installed the latest version from Microsoft site. It also didn't work.
The error occurs even if no project is opened, so the problem is caused either by Visual Studio 2015, by Qt 5.14, or by Qt VS Tools extension.
P.S. Sorry if my english wasn't perfect. Waiting for any ideas on fixing this problem.
For any future readers who have this problem, start your maintenance tool or Qt installer, e.g. C:\Qt\MaintenanceTool.exe, "Add or remove components", and then make sure Qt/<version>/MSVC is installed, as shown in the image below:
.
Then you'll be able to select that Qt version instead of MinGW, since the Visual Studio extension only supports the MSVC compiler and not MinGW.
Encountered the exact same problem and the only solution I have found was reverting to an older version of the Qt Visual Studio Tools extension.
Visual Studio has been painfully persistent about updating the version even once I installed an older one, so make sure to disable automatic extension updates (Extensions → Manage Extensions → Extension Settings → Uncheck Automatically search for updates/Automatically update extensions).
Hope it helps.
To solve your problem, you need to remove the QTDIR and QMAKESPEC environment variables that remain in Windows after installing older versions of Qt.
Well, after some more procedures that didn't help, I just did clean-reinstallation for my Windows 10. Fortunately, that helped :)

Qt <codecvt> : No such file directory

I cant use std::wstring_convert in Qt 5.1, because it said me that <codecvt> : No such file directory. What can I do? I don't know... this code is working at the MSVC 2013.
QtCreator is just a front-end that allows you to edit your source files, it does not contain a compiler. On Windows you need either MinGW or Visual Studio to compile code.
If you want to use Qt 5.1 with Visual Studio 2013, you would have to compile Qt yourself. Digia provides builds for Visual Studio 2010 and 2012. You can find the latest version of Qt here or an old release here.
My advice would be to install Visual Studio 2012 and download a VS2012 build of Qt. Then go to Tools > Options > Build & Run > Kits, click the Add button on the right (or modify the existing one as it probably won't work anyway). Set the compiler to "Microsoft Visual C++ compiler 11.0 (amd64)" if you downloaded the 64 bit version of Qt or "(x86)" if you downloaded the 32 bit version.
Then set the debugger to cdb.exe and the Qt version to the one you just downloaded (if you don't see it, go to the Qt Versions tab at the top, add it, click Apply and the go back to Kits and it should be there). Click ok and your kit should be ready! Make sure that you don't have a warning signal that would point out a potential mistake.
Now open your project and go to the Projects tab (Ctrl + 5) and make sure your project is using the correct Kit.
You should now be all set up properly.
Additionally, if you don't want to install Visual Studio 2012 and want (or have to) work with VS 2013, you can use the Qt 5.3 BETA builds located here. Please note that these builds are in beta and shouldn't be used in production code, if you want to use VS2013 with Qt in production code I would recommend to build Qt 5.2.1 with VS2013, it's not that hard but it can take a while.
You are missing this in your project file:
CONFIG += c++11
You need to make sure that your GCC version (brought to you by mingw) supports that feature though. It is possible that you are using an old version where it was not supported.

Deploying a c++ QT5 app

I am trying to deploy my application. It works on Windows 7 with quit a lot of .dll files but I can't get it work on Windows XP. It seems that windows Xp requires more dll files. But the Dependency walker tool keeps showing me new dll files missing. Now it says API-MS-WIN-CORE-PROCESSTHREADS-L1-1-0.DLL and API-MS-WIN-SECURITY-BASE-L1-1-0.DLL are missing.
When i try to start the exe nothing happens ... no error...
I use Qt5.0.2 with pre build msvc2010.
Thanks in advance
Perhaps this is related to missing VS 2010 redistributable? Also make sure to build in a release-configuration if you don't already know.
http://www.microsoft.com/en-us/download/details.aspx?id=5555
If you package this up into an installer like NSIS, I'd typically execute it with the argument /Q to prevent any GUIs from popping up... it won't ask for any admin privileges which is nice since the previous VC 2008 redistrib always required it.
As the previous answer a requirement is the VS redistributable. In your case, as you use VS2010 the file to download is MS 2010 redistributable.
Besides of that there is the executable windeployqt that helps with the deployment package copying the Qt DLLs required on your executable directory.

How to build Qt for Visual Studio 2010

I struggled finding a how-to which provides a stable solution for using Qt with Visual Studio 2010, so after collecting all the bits of information and some trial and error, I would like to write my solution into a guide.
The problem, or why is it not possible to use prebuilt binaries?
It seems that using binaries built for Visual Studio 2008 might work in some special cases, but I found them not to work. In my case they compiled OK, but they produce runtime errors, like this:
or when started from Visual Studio 2010:
Update: I found a blog post analysing why does it work for some people, while it does not for others. In one word, it depends on whether you have Visual Studio 2008 installed on the same machine, or not.
http://blog.paulnettleship.com/2010/11/11/troubleshooting-visual-studio-2010-and-qt-4-7-integration/
The most important thing (that I stupidly didn’t realize) was the fact that you CANNOT use the Visual Studio 2008 compiled libraries and dll’s (available on the Qt webpage) if you don’t have Visual Studio 2008 installed. The reason is because the Qt SDK you download is a debug build which is dependant on the VC9.0 DebugCRT, meaning it needs the Visual C++ 2008 Debug Runtime installed, which is NOT available as a redistributable installer. The only way to install the DebugCRT is to install the entirety of Visual Studio 2008.
First of all, it’s very important to understand that for using Qt with Visual Studio 2010, it's not possible to use the pre-built binaries which were made for Visual Studio 2008, but you have to compile it from source.
Downloading Qt
On https://www.qt.io/download/
Update 2017: the latest Qt 4.x branch (Qt 4.8.6) has 2 pre-built packages, which are now in the archive section:
http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2010-4.8.6.exe
http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2008-4.8.6.exe
You should not download Qt by clicking "Qt libraries 4.8.6 for Windows (Visual Studio 2008, 218 MB)", but by clicking on the "zip" link above it.
On that link, you get a big zip file like "qt-everywhere-opensource-src-4.8.6.zip". Unzip this into a folder and make its path something nice and small, for example "E:\Qt"
Visual Studio Command Prompt
Now that we have the sources, we need to build the binaries. To do it, open the Microsoft Visual Studio 2010\Visual Studio Tools\Visual Studio Command Prompt (2010) link from your start menu, or even pin it to the taskbar (a good idea). This is a special command prompt which has all the variables set for building with Visual Studio 2010 tools.
Once within the command prompt, navigate to your extracted Qt folder using old-school DOS way, which means you have to change drive letter by E:, enter directories by cd Qt and list dir contents by dir. You can use the tab key for helping you with the directory names. When you have arrived at the correct directory, a dir command should return something like this.
Building Qt
Now it’s time for configure and build. For configuring a minimalist Qt, I'm using the following flags with configure.exe. Just copy and paste it into the command line. Look in the Qt reference manual for what flag to use or not to use.
configure.exe -release -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg
Once configure.exe has finished (it was 10 minutes for me), you'll need to start the build process. It will take about 20-30 minutes with the above flags. To start it, just type:
nmake
Setting environment variables
Basically, we are done. All you need to do is to set your environment variables (QTDIR and PATH), which tell programs where to find Qt. If you are on Windows 7, you can use the following command to set QTDIR to your installation dir.
setx QTDIR e:\Qt
For setting the PATH, I strongly recommend using Path Editor. Within Path Editor
add the directory of Qt\bin to your PATH
(it doesn't matter if it's in system path or user path)
If you prefer to use Control Panel\System\Environment Variables, then you can set these there, too.
Qt Visual Studio Add-in
Here you go, after a logoff-logon or a restart, all the Qt demo applications should start correctly (I recommend have a look at bin\qtdemo.exe). Now you can download and install the Visual Studio Add-in (qt-vs-addin-1.1.9.exe) from the Qt download page, it will work perfectly.
Appendix A: Official Instructions:
There is a page at the official wiki at the Qt website called Qt 4.8 Installing Qt for Windows, but I found it lacking important information.
References
Qt DevNet forums
Recommended flags for a minimalistic Qt build
Building Qt 4.5 with Visual C++ 2010
How to compile Qt as static
Qt 4.8: Configure options for Qt
Edit the PATH environment variable in
Windows without pain - op111.net
Qt V4.8.0 contains prebuilt binaries for Visual Studio 2010 so you don't need to do this anymore:
http://qt.nokia.com/downloads/windows-cpp-vs2010
Refer below link and it might be useful
1)https://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/Build_Instructions/Prerequisites/Qt#Windows_3
2)http://eecs.vanderbilt.edu/research/hmtl/wp/index.php/qt-vs/

Visual C++ 2010 Express: How to use with Qt?

I'm confused about getting Qt working with Visual Studio Express. Most of the searches online have turned up instructions for compiling Qt using instructions such as:
Install MSVC2005 or MSVC2008
Install the most recent Platform SDK (# MSDN: "Platform SDK for Windows
Server 2003 R2")
From the Platform SDK, you'll need to install at least the base +
internet options
Then, download and extract a recent snapshot or the preview release to
D:\Qt\4.x.x
Open up a console with the MSVC settings loaded (see MSVC Tools-menu)
and go to your Qt directory
Type "configure -platform win32-msvc2005" without the quotation
marks
That will build you the project files you'll need
After that, it's as simple as running "nmake" and drinking a lot of
coffee
Then, add D:\Qt\4.x.x\bin and
D:\Qt\4.x.x\lib to your path
environment variable, and you'll be
able to use this version of Qt from
everywhere on your system. The latter
could be added to the library section
in the options from MSVC as well.
(from http://www.qtcentre.org/threads/11710-Visual-Studio-2005-Express)
However, when I go to the download page of Qt (http://qt.nokia.com/downloads), there is a download for Visual Studio labeled:
"Qt libraries 4.7.1 for Windows (VS 2008, 228 MB)"
I'm confused, do I actually still need to build it? Or is it already built?
Using the downloadable exe from qt (http://get.qt.nokia.com/qt/source/qt-win-opensource-4.7.1-vs2008.exe) does not seem to work with Visual Studio 2010. I tried building a simple hello world program from the command line which would not run. I'll repeat my comment from a previous answer.
I tried the hello world example from
doc.qt.nokia.com/4.7/gettingstartedqt.html.
I was able to build the project and an
exe is generated. However, the exe
fails to run and generates a system
error dialog box about "side-by-side
configuration is incorrect...". I ran
SxsTrace and it says:
...
INFO: Begin assembly probing.
INFO: Did not find the assembly in WinSxS.
INFO: Attempt to probe manifest at C:\Windows\assembly\GAC_32\Microsoft.VC90.DebugCRT\ 9.0.21022.8__...\Microsoft.VC90.DebugCRT.DLL.
INFO: Attempt to probe manifest at C:\qthello\debug\Microsoft.VC90.DebugCRT.DLL.
INFO: Attempt to probe manifest at C:\qthello\debug\Microsoft.VC90.DebugCRT.MANIFEST.
INFO: Attempt to probe manifest at C:\qthello\debug\Microsoft.VC90.DebugCRT\Microsoft.VC90.DebugCRT.DLL.
INFO: Attempt to probe manifest at C:\qthello\debug\Microsoft.VC90.DebugCRT\Microsoft.VC90.DebugCRT.MANIFEST.
INFO: Did not find manifest for culture Neutral.
INFO: End assembly probing.
ERROR: Cannot resolve reference Microsoft.VC90.DebugCRT,processorArchitecture="x86", publicKeyToken="...",type="win32",version="9.0.21022.8".
ERROR: Activation Context generation failed.
End Activation Context Generation.
To me, it looks like its trying to use
VS2008 (which I don't have). It makes
sense I guess since the download is
for VS2008.
I was in the process of compiling qt 4.7.1 using the instructions in my question (using win32-msvc2010 as my platform target however) as I asked this SO question and the compilation finished. I rebuilt the hello world project and the exe runs. So it seems like the answer is in order to use with Visual Studio Express 2010 you currently do need to compile (at least until Qt releases a VS2010 download option). However, I believe if you are using VS2008 then you will not need to compile.
The Qt binaries provided by Nokia for Windows target either MinGW or Visual Studio 2008, both for compiling 32bit executables. If you need Qt binaries for VS 2005 (32bit), you may find them in their archives.
For everything else, you need to compile Qt yourself. Especially for:
Visual Studio 2008 64 bit
Visual Studio 2008 Express Edition 64 bit: You need the Windows SDK 7.0 which provides the 64 bit compilers and compile Qt with those.
Visual Studio 2010 32 bit and 64 bit
In general, you cannot link libraries compiled with different compilers, i.e. use the Qt binaries built with VC 9.0 (VS 2008) 32 bit and link them to an executable built with VC 10.0 (VS 2010) 32 bit.
Just a small update on this.
Downloading the QTSDK (and using cmake instead of qmake everything looks like working quite well. Except for the fact that the installer of QTSDK didn't update the path for qmake.exe and you've to do by hand.
Tested with QtSDK 4.8 and visual studio express 2010
http://qt.nokia.com/downloads has a link called qt-vs-addin-1.1.7.exe (57 MB)
You'll probably need that one as well . .
I don't think you need to compile the libraries since there is a download for them now . .
So get the 228 MB of libs and 57 MB plugin and you should be set.
DISCLAIMER: I don't use MSVC (yet?) so please let me know if it works.