while the qt 6.5.1 is Properly installed and also qt vs tools is Properly installed on visual Studio, why I will get a lots of errors about Qt in a normal project using Visual Studio IDE?
-
I'm using Qt 6.5.1 and Visual Studio 2022
I want to use Qt in VS IDE and since I'm using msvcp compiler, I also downloaded Qt 6.6.0 (snapshot from dev) from its maintenance tool:
I also installed the qt vs tools on Visual Studio, added the qt version 6.6.0 using msvcp compiler and then created a simple Qt widget application using the default codes
first I got an error which toled me that the QtMsBuild folder could not be found: I peisted the QtMsBuild folder in to my project folder, but then I got a lots of errors
Severity Code Description Project File Line Suppression State
Error (active) E1696 cannot open source file "QtWidgets/QMainWindow" QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\qtwidgetsapplication4.h 3
Error (active) E1696 cannot open source file "ui_qtwidgetsapplication4.h" QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\qtwidgetsapplication4.h 4
Error (active) E1696 cannot open source file "QtWidgets" QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\stdafx.h 1
Error (active) E0493 no instance of overloaded function "QtWidgetsApplication4::QtWidgetsApplication4" matches the specified type QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\qtwidgetsapplication4.cpp 4
Error (active) E0020 identifier "QWidget" is undefined QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\qtwidgetsapplication4.cpp 4
Error (active) E0130 expected a '{' QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\qtwidgetsapplication4.cpp 5
Error (active) E0262 not a class or struct name QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\qtwidgetsapplication4.h 6
Error (active) E0077 this declaration has no storage class or type specifier QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\qtwidgetsapplication4.h 8
Error (active) E0065 expected a ';' QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\qtwidgetsapplication4.h 10
Error (active) E0276 name followed by '::' must be a class or namespace name QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\qtwidgetsapplication4.h 14
Error C1083 Cannot open include file: 'QtWidgets': No such file or directory QtWidgetsApplication4 E:\QtProjects\QtWidgetsApplication4\stdafx.h 1
I haven't changed a single line of the default codes, but these errors are still exists.
I think some of this errors are related to Qt objects, but why? I'm sure that I've correctly installed qt vs tools on Visual Studio
please guide me. -
@bozorgmehr said:
first I got an error which toled me that the QtMsBuild folder could not be found: I peisted the QtMsBuild folder in to my project folder
Don't do that. Those files are not part of your project. QtMsBuild is installed as part of the VS extension. The path to it should be set automatically during installation, but if it's not then go to Tools -> Options -> Qt -> Qt/MSBuild and set the path to it manually. It should be something like
C:\Users\<user name>\Appdata\Local\QtMsBuild
. Make sure the folder is there, otherwise it might mean that the extension did not install correctly for some reason. This setting corresponds to the environment variable QtMsBuild, so you can check if it's set on your system.but then I got a lots of errors
They all mean that you don't have widgets module added in your project. Right click on your project in Solution Explorer, go to Qt -> Qt Project Settings -> General -> Qt Modules and make sure the
widgets
module is on the list. If not then click the little arrow at the end of the line, Select Modules and check the Qt Widgets module. Make sure you do that for both Release and Debug configuration. -
@Chris-Kawa, first, on qt project settings when I click qt modules an edit box will came, and there is no lists: why?
I typed QT Widget but then, after compiling I got 300 errors about the msvcp folder in folder qt 6.6.0 snapshot from dev.
I then created another qt widgets application, but again the saim errors.
I will send some of the errors here.
Severity Code Description Project File Line Suppression State
Error (active) E0325 inline specifier allowed on function declarations only QtWidgetsApplication5 E:\Qt\Qt\6.6.0\msvc2019_64\include\QtCore\qcontainerinfo.h 76
Error (active) E2386 'constexpr' is not valid here QtWidgetsApplication5 E:\Qt\Qt\6.6.0\msvc2019_64\include\QtCore\qanystringview.h 301
Error (active) E2860 a nonstatic data member cannot be declared as inline QtWidgetsApplication5 E:\Qt\Qt\6.6.0\msvc2019_64\include\QtCore\qanystringview.h 301
Error C1189 #error: "Qt requires a C++17 compiler, and a suitable value for __cplusplus. On MSVC, you must pass the /Zc:__cplusplus option to the compiler." (compiling source file QtWidgetsApplication5.cpp) QtWidgetsApplication5 E:\Qt\Qt\6.6.0\msvc2019_64\include\QtCore\qcompilerdetection.h 1223
how to fix? -
@bozorgmehr said:
I click qt modules an edit box will came, and there is no lists: why?
Sounds like you don't have your installed Qt added to the extension options. Open Tools -> Options -> Qt -> Versions and add your Qt installation directory there. Then you can go to your project options and select that version for your project. This should populate the list of available modules.
-
okay, and what about this errors about the msvcp folder in qt? I then created another qt widgets application, but again the saim errors.
I will send some of the errors here.
Severity Code Description Project File Line Suppression State
Error (active) E0325 inline specifier allowed on function declarations only QtWidgetsApplication5 E:\Qt\Qt\6.6.0\msvc2019_64\include\QtCore\qcontainerinfo.h 76
Error (active) E2386 'constexpr' is not valid here QtWidgetsApplication5 E:\Qt\Qt\6.6.0\msvc2019_64\include\QtCore\qanystringview.h 301
Error (active) E2860 a nonstatic data member cannot be declared as inline QtWidgetsApplication5 E:\Qt\Qt\6.6.0\msvc2019_64\include\QtCore\qanystringview.h 301
Error C1189 #error: "Qt requires a C++17 compiler, and a suitable value for __cplusplus. On MSVC, you must pass the /Zc:__cplusplus option to the compiler." (compiling source file QtWidgetsApplication5.cpp) QtWidgetsApplication5 E:\Qt\Qt\6.6.0\msvc2019_64\include\QtCore\qcompilerdetection.h 1223
how to fix? -
@bozorgmehr As the error says Qt6 requires at least C++17 standard, so go to your project settings -> General -> C++ Language Standard and make sure it's set to C++17 (or higher).
-
@Chris-Kawa okay, I've changed the project settings and it Compiled successfully, but when running the EXE file I will get these errors
QWidgetsApplication8.exe - System Error dialog The code execution cannot proceed because Qt6Cored.dll was not found. Reinstalling the program may fix this problem.
QtWidgetsApplication8.exe - System Error dialog The code execution cannot proceed because Qt6Widgetsd.dll was not found. Reinstalling the program may fix this problem.
I'm sure that the QT installation path is added to path in Environment Variables.
But still this error is exists: I even used the clean option and then rebuild, but still this error is. -
@bozorgmehr said in while the qt 6.5.1 is Properly installed and also qt vs tools is Properly installed on visual Studio, why I will get a lots of errors about Qt in a normal project using Visual Studio IDE?:
I'm sure that the QT installation path is added to path in Environment Variables.
If it would then you would not get those error.
-
When I said that I have added the qt installed path to the path variable, but I get an error, why do you say that if you had added the qt installed path to the path variable, you would not get an error? I am saying that I have done this but I get an error
-
@bozorgmehr said in while the qt 6.5.1 is Properly installed and also qt vs tools is Properly installed on visual Studio, why I will get a lots of errors about Qt in a normal project using Visual Studio IDE?:
I am saying that I have done this but I get an error
Then may it be so - happy searching for another solution.
When the correct path to a dll is in the PATH environment var then noone will get an error that this dll can not be found. -
@bozorgmehr
Out of interest, what happens if you try to run your executable from a Command Prompt, quite outside of VS? -
@bozorgmehr said:
I'm sure that the QT installation path is added to path in Environment Variables
Don't add Qt installation to your PATH. You would have to add both the bin and plugin directories. That's a terrible practice and you can't expect your users to do so either. You should properly deploy your app. See windeployqt. Run it on your exe and it will copy all the necessary files to your app dir.
-
@Chris-Kawa said in while the qt 6.5.1 is Properly installed and also qt vs tools is Properly installed on visual Studio, why I will get a lots of errors about Qt in a normal project using Visual Studio IDE?:
Run it on your exe and it will copy all the necessary files to your app dir.
If my build system would copy me all the Qt dlls around on every time I build the project I would throw it away. Not to say that imo it does not copy the debug dlls (but I may be wrong) so it does not work for debug.
-
@Christian-Ehrlicher said:
If my build system would copy me all the Qt dlls around on every time I build the project I would throw it away.
Thankfully most build systems are very configurable and you can do it the exact amount of times that is needed. Usually once :)
And I know Linux people prefer to have one copy of libraries on the system, but, at least on Windows, local deployment is the only sane way to have your apps. PATH should be off limits for such things. OP already mentioned two different versions of Qt installed. Adding any of them to PATH is a recipe for disaster sooner or later (probably sooner).
Not to say that imo it does not copy the debug dlls (but I may be wrong) so it does not work for debug.
Good news - it does!
-
thanks, my problem solved.
-
-
-