首页 > 解决方案 > VS2019 无法正确导入 Qt Designer 项目

问题描述

我到处寻找解决方案,但我找不到。在 VS2019 中,我安装了 Qt 工具扩展,并从 Qt Designer 中导出了 C++ 头文件,包括我的项目。然后我创建了一个 .pro 文件,包括:

QT += widgets
QT += uitools

HEADERS += ui_xinterface.h
FORMS += xinterface.ui
SOURCES += main.cpp

然后我将它导入到 VS2019 中,它会自动创建一个项目。然后我将此函数添加到 main.cpp,按照此示例(注意:main.cpp 最初是一个空文件):

#include <QtUiTools>
#include "ui_xinterface.h"

static QWidget* loadUiFile(QWidget* parent)
{
    QFile file(":/forms/xinterface.ui");
    file.open(QIODevice::ReadOnly);

    QUiLoader loader;
    return loader.load(&file, parent);
}

这没有建立:

Build started...
1>------ Build started: Project: ui_interface, Configuration: Debug x64 ------
1>main.cpp
1>Qt6EntryPointd.lib(qtentrypoint_win.cpp.obj) : error LNK2019: unresolved external symbol main referenced in function WinMain
1>debug\\ui_interface.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "ui_interface.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

并给出了 9 个错误:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK1120 1 unresolved externals  ui_interface    C:\Users\User\Documents\EE\basic-app\debug\ui_interface.exe 1   
Error   LNK2019 unresolved external symbol main referenced in function WinMain  ui_interface    C:\Users\User\Documents\EE\basic-app\Qt6EntryPointd.lib(qtentrypoint_win.cpp.obj)   1   
Error (active)  E2422   defaulted default constructor cannot be constexpr because the corresponding implicitly declared default constructor would not be constexpr  ui_interface    C:\Qt\6.2.0\msvc2019_64\include\QtCore\qmetatype.h  444 
Error (active)  E0028   expression must have a constant value   ui_interface    C:\Qt\6.2.0\msvc2019_64\include\QtCore\qmetatype.h  2181    
Error (active)  E0028   expression must have a constant value   ui_interface    C:\Qt\6.2.0\msvc2019_64\include\QtCore\qmetatype.h  2261    
Error (active)  E2422   defaulted default constructor cannot be constexpr because the corresponding implicitly declared default constructor would not be constexpr  ui_interface    C:\Qt\6.2.0\msvc2019_64\include\QtCore\qmutex.h 150 
Error (active)  E2422   defaulted default constructor cannot be constexpr because the corresponding implicitly declared default constructor would not be constexpr  ui_interface    C:\Qt\6.2.0\msvc2019_64\include\QtCore\qmutex.h 205 
Error (active)  E2422   defaulted default constructor cannot be constexpr because the corresponding implicitly declared default constructor would not be constexpr  ui_interface    C:\Qt\6.2.0\msvc2019_64\include\QtCore\qproperty.h  255 
Error (active)  E2422   defaulted default constructor cannot be constexpr because the corresponding implicitly declared default constructor would not be constexpr  ui_interface    C:\Qt\6.2.0\msvc2019_64\include\QtCore\qrunnable.h  56* 

这些看起来像是链接器错误,但我不知道如何修复它们。附加库 [$(Qt_INCLUDEPATH_)] 和目录 [$(Qt_LIBPATH_)] 似乎在项目属性中自动链接。我对此很陌生,我错过了什么?

标签: c++qtvisual-studio-2019qt-designerqt6

解决方案


推荐阅读