Подключить Qt библиотеки в Visual Studio для UE4
Как можно подключить Qt библиотеки в Visual studio для Unreal engine 4?
Как я понял, у Unreal engine 4 своя система сборки через файл C# - *.Build.cs и поэтому через свойства проекта не получится подключить библиотеки, там просто отсутствует вкладка "C++" которая описана во всех подобных туториалах.
При попытке указать через файл *.Build.cs путь к библиотеки и подключаемую .dll проект не собирается и ругается на эту dll.
PrivateIncludePaths.Add("c:/Qt/5.14.2/msvc2017_64/include/");
PublicAdditionalLibraries.Add("c:/Qt/5.14.2/msvc2017_64/bin/Qt5Core.dll");
Как правильно указать пути к файлам .h, .lib, .dll в связке VS/UE4?
Ответы (1 шт):
Итак, чтоб добавить Qt библиотеки в UE4. Покажу на примере Qt5Core.dll/lib
- Вам нужен msvc2017_64 который указывается при установке QtCreator и установленная поверх Visual studio расширение Qt VS Tools
- Создать проект UE4 с использованием C++
- В Корневой папке проекта создать дополнительные папки У меня в данном случае они указаны вот так:
[Корневая папка вашего проекта]/ThirdParty/Qt/Includes/QtCore
[Корневая папка вашего проекта]/ThirdParty/Qt/Libraries/Win64
- Из корневой папки Qt перенести нужные файлы:
В моём случае находим в C:\Qt\Qt5.13.0\5.13.0\msvc2017_64\include\QtCore
и перетаскиваем все файлы в [Корневая папка вашего проекта]/ThirdParty/Qt/Includes/QtCore

В папке C:\Qt\Qt5.13.0\5.13.0\msvc2017_64\lib находим Qt5Core.lib и Qt5Cored.lib
и копируем в [Корневая папка вашего проекта]/ThirdParty/Qt/Libraries/Win64
В папке C:\Qt\Qt5.13.0\5.13.0\msvc2017_64\bin находим Qt5Core.dll и Qt5Cored.lib
и копируем в [Корневая папка вашего проекта]/ThirdParty/Qt/Libraries/Win64
- Открываем ваш проект через visual studio и находим файл [Имя вашего проекта].build.cs и меняем его. В данном случае у меня проект называется "InfProject2" измените на собственное имя проекта.
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
using System.IO;
using UnrealBuildTool;
public class InfProject2 : ModuleRules
{
private string ModulePath
{
get { return ModuleDirectory; }
}
private string ThirdPartyPath
{
get { return Path.GetFullPath(Path.Combine(ModuleDirectory, "../../ThirdParty/")); }
}
public InfProject2(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" , "RHI", "RenderCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
PrivateIncludePaths.Add("D:/Program Files/Epic Games/UE_4.24/Engine/Source/Runtime/Launch/Public/");
LoadQt(Target);
/*
//Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
*/
}
public bool LoadQt(ReadOnlyTargetRules Target)
{
// Start OpenCV linking here!
bool isLibrarySupported = false;
// Create OpenCV Path
string QtPath = Path.Combine(ThirdPartyPath, "Qt");
// Get Library Path
string LibPath = "";
bool isdebug = Target.Configuration == UnrealTargetConfiguration.Debug;
if (Target.Platform == UnrealTargetPlatform.Win64)
{
LibPath = Path.Combine(QtPath, "Libraries", "Win64");
isLibrarySupported = true;
}
else
{
string Err = string.Format("{0} dedicated server is made to depend on {1}. We want to avoid this, please correct module dependencies.", Target.Platform.ToString(), this.ToString()); System.Console.WriteLine(Err);
}
if (isLibrarySupported)
{
//Add Include path
PublicIncludePaths.AddRange(new string[] { Path.Combine(QtPath, "Includes") });
// Add Library Path
PublicLibraryPaths.Add(LibPath);
//Add Static Libraries
PublicAdditionalLibraries.Add("Qt5Core.lib");
//Add Dynamic Libraries
PublicDelayLoadDLLs.Add("Qt5Core.dll");
}
PublicDefinitions.Add(string.Format("WITH_QT_BINDING={0}", isLibrarySupported ? 1 : 0));
return isLibrarySupported;
}
}
Создайте Новый класс C++ через Unreal engine 4 и подключите библиотеку в .cpp файл созданного класса
#include "QtCore/qstring.h"
в конструкторе указываем
AOwlActorAndroid::AOwlActorAndroid()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
QString str = "QT";
GEngine -> AddOnScreenDebugMessage(-1, 5.f, FColor::Red, str.toStdString().c_str());
}
Больше информации можно узнать здесь https://www.ue4community.wiki/Legacy/Detailed_Account_Of_Integrating_OpenCV_Into_UE4_With_VS2017



