Qt with visual studio , Qt requires a c++17 compiler - c++

I'm stuck on this, when i compile a project in Visual Studio i have this error at the ouput, telling that:
on nmvc you must the /Zc:__cplusplus option to the compiler (compiling source file QtdesignerWidget.cpp)
I tried the solution to add /Zc:__cplusplus in the project properties -C++ / Command line / Additional options withou success
And when i try to make a .pro file in QT VS tools it makes this error:
Warning : Cannot Find any Qt4 projects to export

Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.
Select the Configuration Properties > C/C++ > Command Line property page.
Add /Zc:__cplusplus or /Zc:__cplusplus- to the Additional options: pane.
The answer is taken from here: https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170

Same problem. Here are my platforms:
Qt version: 6.2.0
Qt Visual Studio Tools version: 3.4
Compiler version: VS2019_64
Luckily, I also installed Qt5.14.2 on my computer. When I changed configurations to: Qt5.14.2 and VS2017_64. Problem solved. So I guess VS2019 or Qt VS tools3.4 doesn't work well with Qt6.2.0.
You can have a try.

Are you sure your language standard is set to C++17 in the project settings?
Go to project properties --> General --> C++ Language Standard
In my case it was default set to C++14. This must be set to C++17.

Related

Visual Studio 2019 C++ and std::filesystem

Now, I would have not expected That, after 'upgrading' to a 'newer' version of the compiler.
In VS2017 std::filesystem was available through std::experimental::filesystem, Now after upgrading to VS2019 to my surprise it is not available at all. Not in std::experimental nor std::filesystem.
and YES, I've tried setting c++17 from project's settings even the 'latest draft' thing, any ideas?
For the sake of completeness and people searching this in the future.
To switch to C++17' std::filesystem in Visual Studio (regardless VS2019 or VS2017) you need to:
change the language standard in Project properties -> Configuration Properties -> C/C++ -> Language -> C++ Language Standard to at least ISO C++17 Standard (/std:c++17)
(Can also be found in Project properties -> Configuration Properties -> General -> C++ Language Standard)
change #include <experimental/filesystem> to #include <filesystem>
change in the source code all appearance of std::experimental::filesystem to std::filesystem
fix the possible differences between the experimental and final filesystem versions
For all those who struggle with porting their existing Visual Studio 2017 projects into Visual Studio 2019, having proper project settings and pulling their hair out to no avail:
in file VC\Tools\MSVC\14.26.28801\include\filesystem
there's:
#if !_HAS_CXX17
now for why this flag is not automatically being set when changing projects settings I have no idea.
Thus I've used:
#define _HAS_CXX17 1
#include <filesystem>
in my files as a workaround. Works fine.
Update: On another system, within project's file there was
<LanguageStandard>stdcpplatest</LanguageStandard>
<AdditionalOptions>/std:c++14 %(AdditionalOptions)</AdditionalOptions>
The latter line was resulting in problems (obviously). Switching higher-level project settings does not remove such optional settings (obviously).
I hit the same issue [include filesystem] with the 2019 version (Microsoft Visual Studio Community 2019 Version 16.6.0) in spite of C++17 language selection.
I had to explicitly change the platform and the Active Solution platform to x64 in the configuration window (though, I started with x64). With this, the error is gone.
You will have to update your Visual C++ redistributable if you haven't. Then under project properties > Configuration Properties > C++ Language Standard: Select C++17 or higher.
You could try setting it to that by default. See this:How to change default C++ language standard in Visual Studio 2019?
The correct solution to that is:
For Xcode:
go to project properties
under build Settings, scroll down to Apple Clang- Language- c++.
there you have to select c++ language dialect and set it to C++17[-std=c++17].
cheers
Singh

Configure QtPackage for Visual Studio by command line

I'm trying to build a project which uses qt on an CI service for windows.
I already managed to install the QtPackage for Visual Studio by command line.
Now I'm stuck at the following step:
Launch VS2015 for configuring Qt5Package
QT5 > Qt Options > Add
Version name: Qt 5.6.22Win32
Path: C:\build\libs\qt5_6_2\qtbase
Default Qt/Win version: Qt 5.6.2 Win32 – OK - You may need to restart Visual Studio for this to take effect.
Is is possible to do this from the command line? If not, how can I work around this problem?
If you are willing to modify such global setting (for all projects), I'm sorry but there is no way to do it from command line in current public versions of the QtVSTools, nor in the latest version from the repository head (https://code.qt.io/cgit/qt-labs/vstools.git/ # 2018-01-09).
On the other hand, if you use msbuild to compile the project, you can override the Qt version to be used during that compilation (project files are not modified).
To do so, change the QTDIR project property (using the /property option) and indicate the path to the directory of Qt version you want to use:
msbuild your_solution.sln /property:QTDIR="C:\build\libs\qt5_6_2\qtbase"
Hope this helps.

cpp:-1: error: C1041: cannot open program database; untitled-build-desktop-debug\vc120.pdb'

All the answers available for this problem are solutions for Visual studio. I am facing this problem in QT. I run a sample example but this error pops up.Could somebody help.
error: C1041: cannot open program database 'c:\users\newfolder\untitled-build-desktop-debug\vc120.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS
right click on project-> properties->c/c++ -> output files:
in Program Database File Name: include the project name with path. (.../../../../release/ProjectName/)
This approaches works for me.
(This answer may or may not only apply to those who have built QT from source.)
Ensure you are building with the same Visual Studio toolchain version that your QT distribution was built for.
I got this error when I used a build kit (Options -> Build & Run -> Kits) that was configured to use MSVC 2013 (12.0), but the QT Version was msvc2010_opengl. Apparently the discrepancy led to an invalid build configuration. Modifying the build kit to use VS 2010 fixed the problem.

Visual Studio 2012 C++ How to add compiler option in NMake project

I am currently modifying on a open-source project to suit my own need, however, the project to be built (or compiler) requires me to add a /EHsc option to cl.exe
I am using Microsoft Visual Studio 2012 to work on the project. I have been searching long enough but I cannot find the solution still.
Is it possible to add a flag via MS Visual Studio 2012? Because I saw the output log displaying that compiler (cl.exe) compiled with various flag in this project such as /nologo /c /WX.
How can I add the options to cl.exe with this IDE?
Project working on : SumatraPDF
[Edit #1] After reading the first answer provided below, this is the screen I got, it doesn't seem there is an option to do so.
Update: From the screenshot you posted, it seems the SumatraPDF project is NMake-based.
Therefore, you will have to add /EHsc to the build command line, using the NMake property page described here, or edit the Makefile directly.
Original, misguided answer follows:
Per MSDN:
To set this compiler option in the Visual Studio development
environment
Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.
Select the C/C++ folder.
Select the Code Generation property page.
Modify the Enable C++ Exceptions property.
Or, set Enable C++ Exceptions to No, and then on the Command Line
property page, in the Additional Options box, add the compiler option.

"There's no Qt version assigned to this project for platform Win32" - visual studio plugin for Qt

I have a Qt project I am working on in Visual Studio 2010, with the Qt Visual Studio Add-in (for Qt 4.8). The project is running fine on my work machine, and I am trying to run it on my home machine. When I try to build, I get the following error:
There's no Qt version assigned to this project for platform Win32.
Please use the 'change Qt version' feature and choose a valid Qt
version for this platform.
However, it's set up to use a valid Qt version (another project I'm working on at home uses this plugin as well). Why is this occurring? When I got to Qt -> Qt Options, I see a valid version (4.8.0). Thanks
Did you select a proper Qt version in the Qt settings of your project?
More detailed:
If you right-click on the project there should be a "Qt Project Settings" option (or similar - I use the german version) near the end of the context menu. In there you can set the Qt version that this specific project uses. Is this one possibly not set correctly?
Solution:
Right click your project;
Qt Project Settings;
Under the Properties tab, you will find the option Version;
change it to a proper value;
Now, go ahead with your project.
Hope to help
Had the same problem with a x64 Visual Studio 2019 solution on Windows using Qt 5.15.0. Based on the answer from #Fabian and the excellent comment from #sitting-duck:
Install the Qt VS Tools extension
Select Extensions > Qt VS Tools > Qt Options
On the Qt Versions tab click Add
Set "Version Name" to something like "Qt-5.15.0"
Set "Path" to "[QT-PATH]\5.15.0\msvc2019_64"
Open Project Properties > Qt Project Settings > General > Qt Installation
Ensure this is set to "Qt-5.15.0" and close Project Properties
Right-click the solution (in the Solution Explorer tab) and select Change Solution's Qt Version
Ensure Qt-5.15.0 is selected
You should be good to go.
Open vcxproj file in a notepad, look for QtVersion...something=...
Ensure that the version value is really 4.8.0 (or whatever is your actual QT SDK version).
I found this issue too. and I found the solution .
you must keep the Qt version name is exactly same with the project create using.
which you think u can change freely,but actually not.
If you want to move Qt project between different computers, it's a good idea to use the qt project file, and not the MSVC (.vcxproj) one. So when you move from your work machine home, create a .pro file (in the Qt menu, you find the neccessary options to do that), and then load the .pro file at home, again using the Qt menu inside MSVC.
Another thing this could be is the platform being used is not the platform you think it is. In MSVC right-click on project, select properties, and then press configuration manager. Then check that all configurations and platforms are as you expect them to be.
I got the same problem during migration from Qt5.9 to Qt5.10.
We have a solution (Visual Studio) which consists of many projects. Some of them have QtVersion = "Qt5.9" and others have QtVersion = "Qt5.7" (yes, it were inaccurate project settings)
So, after I change all Qt project's settings from 5.9 to 5.10 automatically and remove Qt5.7 from versions list - I got the same error. This error was fixed trivially - I just add back Qt5.7 to the versions list (temporary until ALL projects' Qt version was not changed to 5.10).
In my case, I ported a Visual Studio project, with all its files (including .sln, .vcxproj, etc) to another computer using git. When I set everything up on the new computer, I accidentally selected a different folder for the Qt executables in VS (I selected C:\Qt\5.9.9\winrt_x86_msvc2017 instead of C:\Qt\5.9.9\msvc2017_64). When I double-checked which I had selected on the original computer, and then selected the same on the new computer, all was good.
To select a Qt folder: Extensions -> Qt VS Tools -> Qt Options -> Add -> Path (Version Name is auto-filled once you select the path).
This all describes the process using Visual Studio 2019, with the Qt plugin found here.
You could follow AlainD's instruction.
It work for me.
Just Right-click on Solution -> Change Solution's Qt Version
It will make change for its all projects.