尝试在 Qt 中获取自定义 window 框架时出现 LNK2019 问题

LNK2019 problems when trying to get custom window frame in Qt

我想要一个应用程序的自定义 window 框架,我在 Qt 5.4 中制作并 QML.Before 在我的主项目中实现它,我在默认应用程序中尝试了以下操作:

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

From the doc:

For the purposes of porting older applications, the QtDeclarative module is still available in Qt 5 but has been renamed to Qt Quick 1. Applications that required Qt Quick 1 specific API (e.g. QDeclarativeView or QDeclarativeItem and the Graphics View integration) can use this module. Note that new applications should use the new Qt QML and Qt Quick modules instead.

To use the Qt Quick 1 module, add "declarative" to your qmake .pro file:

Required header files can be included as follows:

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

还有:

All classes that were previously in the QtDeclarative module have been moved into the Qt QML and Qt Quick modules, and their class names have been changed to reflect their new module locations. The class name changes are as follows:

... QDeclarativeView -> QQuickView

但是:

(The QtDeclarative module is still available to developers as the Qt Quick 1 module, as discussed below. However, it should not be used for new applications.)