I have created a Qt5 application with Visual Studio (2019). When I compile and launch the application, everything goes well but if I try to launch it by hand, in other words by double clicking on the .exe file and not by clicking on 'Local Windows Debugger', I get errors like:
error
For the translation: "Unable to execute the code, because QtWidgetsd.dll is
not found. Reinstalling the program may fix this problem.
problem". I get 3 messages each time with QtWidgetsd.dll
, QtCored.dll
, QtGuid.dll
that are missing.
So I copied the .dll from Qt/5.15.2/msvc2019_64/bin
But another error appears:
error2
I have been searching for a long time, reinstalling visual studio, changing the qt5 configuration in VS but nothing changes.
Thanks in advance for any help you can provide
CodePudding user response:
There are two possible solutions:
First solution
Use windeployqt
to copy all the required dlls
. But I don't like this solution.
Second solution
Use Cmake
correctly to link the dlls
you can do that by adding these lines to your CMakeLists.txt
file:
find_package(Qt5 COMPONENTS Widgets REQUIRED) # Add all used qt packages
target_link_libraries(CMAKE_PROJECT_NAME PUBLIC Qt5::Widgets) # Add all used libraries.