尝试在Qt中获取自定义窗口框架时LNK2019问题

LNK2019 problems when trying to get custom window frame in Qt

本文关键字:框架 窗口 LNK2019 问题 自定义 获取 Qt      更新时间:2023-10-16

我想要一个自定义窗口框架,用于我在Qt 5.4中使用QML制作的应用程序。在我的主项目上实现它之前,我在默认应用程序上尝试了以下内容:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    //QQmlApplicationEngine engine;
    //engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    QDeclarativeView view;
    viewsetWindowFlags(Qt::FramelessWindowHint
           | Qt::WindowSystemMenuHint
           | Qt::WindowMinimizeButtonHint
           | Qt::Window);
    view.setAttribute(Qt::WA_TranslucentBackground);
    view.setMaximumHeight(640);
    view.setMaximumWidth(350);
    view.viewport()->setAutoFillBackground(false);
    view.show();
    return app.exec();
}

这是.pro文件:

TEMPLATE = app
QT += qml quick widgets
QT += core gui widgets quick
QT += network
SOURCES += main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)

错误:

main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QDeclarativeDebuggingEnabler::QDeclarativeDebuggingEnabler(void)" (__imp_??0QDeclarativeDebuggingEnabler@@QEAA@XZ) referenced in function "void __cdecl `dynamic initializer for 'qmlEnableDebuggingHelper''(void)" (??__EqmlEnableDebuggingHelper@@YAXXZ)
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QDeclarativeView::QDeclarativeView(class QWidget *)" (__imp_??0QDeclarativeView@@QEAA@PEAVQWidget@@@Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QDeclarativeView::~QDeclarativeView(void)" (__imp_??1QDeclarativeView@@UEAA@XZ) referenced in function main

我知道这与我的 .pro 文件有关,但在理解 LNk 错误方面不太好,到目前为止,我已经尝试了不同的事情但没有进展。如何解决这个问题?

添加到 pro 文件:

QT += declarative

从文档中:

为了移植较旧的应用程序,Qt声明式 模块在Qt 5中仍然可用,但已重命名为Qt Quick 1。 需要Qt Quick 1特定API的应用程序(例如 QDeclarativeView 或 QDeclarativeItem 和图形视图 集成)可以使用此模块。请注意,新应用程序应 改用新的Qt QML和Qt Quick模块。

要使用Qt Quick 1模块,请将"声明式"添加到qmake .pro 文件:

可以包含所需的头文件,如下所示:

#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeItem>

也:

以前在 Qt声明式模块中的所有类都是 移到Qt QML和Qt Quick模块中,它们的类名有 已更改以反映其新模块位置。类名 更改如下:

。QDeclarativeView -> QQuickView

但:

(QtDeclarative模块仍可作为Qt提供给开发人员 快速 1 模块,如下所述。但是,它不应用于 新应用程序。