Search code examples
c++qtqmllnk2019

LNK2019 problems when trying to get custom window frame in Qt


I want a custom window frame for an app I've made in Qt 5.4 with QML.Before implementing it on my main project, I tried the following on a default application:

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();
}

Here is the .pro file:

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)

The errors:

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

I know this is related to my .pro file but not too good in understanding LNk errors, I've tried different things but no progress, till now. How to fix this?


Solution

  • Add to the pro file:

    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>
    

    Also:

    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

    But:

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