Use vcpkg with the following command:
vcpkg install qt5:x64-windows-static
This is necessary for using any static libraries with vcpkg:
Configuration Properties/Vcpkg/Use static libraries
: Yes
Configuration Properties/"C/C++"/Code Generation/Runtime Library
: /MT
for release, /MTd
for debug (switch Conguration
on top left) This is necessary because vcpkg compiles static libraries with /MT
.
#include <QtCore/QtPlugin>
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QLabel>
#include <iostream>
int main(int argc, char* argv[])
{
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
std::cout << "Hello World!\n" << QT_VERSION_STR << "\n";
QApplication application(argc, argv);
QMainWindow mainWindow;
QLabel* label = new QLabel(&mainWindow);
label->setText("first line\nsecond line");
mainWindow.show();
return application.exec();
}
You will encounter many linker errors and Google each of them. I ended up with the following list:
Configuration Properties/Linker/Input/Additional Dependencies
for release:
imm32.lib
winmm.lib
Ws2_32.lib
Version.lib
Netapi32.lib
iphlpapi.lib
userenv.lib
psapi.lib
CRYPT32.LIB
Wtsapi32.lib
Dwmapi.lib
"E:\vcpkg\installed\x64-windows-static\plugins\platforms\qwindows.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Core.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Gui.lib"
"E:\vcpkg\installed\x64-windows-static\lib\Qt5Widgets.lib"
Configuration Properties/Linker/Input/Additional Dependencies
for debug:
imm32.lib
winmm.lib
Ws2_32.lib
Version.lib
Netapi32.lib
iphlpapi.lib
userenv.lib
psapi.lib
CRYPT32.LIB
Wtsapi32.lib
Dwmapi.lib
"E:\vcpkg\installed\x64-windows-static\debug\plugins\platforms\qwindowsd.lib"
"E:\vcpkg\installed\x64-windows-static\debug\lib\Qt5Cored.lib"
"E:\vcpkg\installed\x64-windows-static\debug\lib\Qt5Guid.lib"
"E:\vcpkg\installed\x64-windows-static\debug\lib\Qt5Widgetsd.lib"
Many are accessible easily through English Google, but here are two key resources in foreign languages:
- CMake
- Compile UI files
- How to include directly e.g.
<QApplication>
instead of<QtWidgets/QApplication>
- Linker input path with environmental variables
Another (crazy) list of dependencies: