c++ - 尝试在 Qt 中获取自定义窗口框架时出现 LNK2019 问题

标签 c++ qt qml lnk2019

我想为我在 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

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.)

关于c++ - 尝试在 Qt 中获取自定义窗口框架时出现 LNK2019 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27836236/

相关文章:

c++ - 数字 xor K - K = 数字 + K xor K,为什么?

c++ - C++ 中具有不同数据成员的模板结构

c++ - 将 C++ 信号发送到 QML

c++ - 将 VS2008 转换为 VS2010 项目 "cannot find the file specified"

c++ - 在 C++ 中获取 Vector 的一部分,例如指向 C 数组中间的指针

c++ - Qt中的logicalDpiX和physicalDpiX有什么区别?

qt - QML - 跟踪组件的全局位置

c++ - Qt - 获取两个日期时间对象之间的时间跨度

qt - 替换 console.debug() 的日志记录后端 console.warn()

qt - 如何将 QML View 嵌入 native 窗口