Qt5, VTK7, QtCreator: QVTKWidget linker error

1.5k Views Asked by At

I'm attempting to build an application with QTCreator on Windows10 that uses the QVTKWidget, but I get linker error(s):

mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QVTKWidget::QVTKWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" referenced in function "public: void __cdecl Ui_MainWindow::setupUi(class QMainWindow *)"

I've downloaded Qt5.5 for msvc2013 and msvc2013_64. I've downloaded VTK7, and built it with Qt support using CMake. I built a vtk32 and vtk64. I've copied D:\VTK\vtk32\bin\Release\QVTKWidgetPlugin.dll to C:\Qt\Tools\QtCreator\bin\plugins\designer and when I start QTCreator, the QVTKWidget shows up on the bottom under the QVTK section of the available form controls.

I add the QVTKWidget to my form and build the application using msvc2013 Release. Then I get the linker errors. What lib am I missing?

Below is my .pro file

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = MIViewer
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

win32 {
    INCLUDEPATH += D:\VTK\VTK-7.0.0\GUISupport\Qt
    INCLUDEPATH += D:\VTK\VTK-7.0.0\Common\Core
    INCLUDEPATH += D:\VTK\VTK-7.0.0\Rendering\Core
}

win32-msvc2013 {
    INCLUDEPATH += D:\VTK\vtk32\GUISupport\Qt
    INCLUDEPATH += D:\VTK\vtk32\Interaction\Style
    INCLUDEPATH += D:\VTK\vtk32\Rendering\Core
    INCLUDEPATH += D:\VTK\vtk32\Rendering\OpenGL2
    INCLUDEPATH += D:\VTK\vtk32\Common\Core
    LIBS += -LD:\VTK\vtk32\lib\Release
}

win32-msvc2013_64 {
    INCLUDEPATH += D:\VTK\vtk64\GUISupport\Qt
    INCLUDEPATH += D:\VTK\vtk64\Interaction\Style
    INCLUDEPATH += D:\VTK\vtk64\Rendering\Core
    INCLUDEPATH += D:\VTK\vtk64\Rendering\OpenGL2
    INCLUDEPATH += D:\VTK\vtk64\Common\Core
    LIBS += -LD:\VTK\vtk64\lib\Release
}

LIBS += -lQVTKWidgetPlugin \
        -lvtkGUISupportQt-7.0 \
        -lvtkRenderingQt-7.0
1

There are 1 best solutions below

0
On

Just wanted to answer my own question in case anyone else comes across this post with a similar program. I was able fix this by re-compiling the 32-bit VTK with all of the Cmake Qt options selected and paths filled out. I didn't have the correct paths in CMake, but cmake didn't complain and generated the VS solution files. And I didn't notice that 20% of the projects had failed until I tried to re-compile VTK.

When trying to diagnose linker errors, it's nothing mysterious. There's something missing! Just going through the checklist of dependencies one by one solved it for me.