Reputation: 1047
After lots of trouble I finally managed to set up VTK with QT using Visual Studio. The setup was done using cmake.
The versions I use are:
My first goal was to be able to run examples like this.
I'm able to run that examples and others in Release mode in VS and correctly run the executables.
The problem is when I set it to Debug Mode I will end up with an Error:
The program '[9520] SideBySideRenderWindowsQt.exe' has exited with code 1 (0x1).
After a few tries I found out that in Debug mode, whenever a QVTKWidget is created:
QVTKWidget *qvtkWidgetLeft;
(...)
qvtkWidgetLeft = new QVTKWidget(centralwidget);
I get the above error.
I've set up a debugger in QTcreator following this post How to configure CDB in Qt Creator?
EDIT:
The callstack if it helps:
> SideBySideRenderWindowsQt.exe!QFlags<enum Qt::WindowType>::QFlags<enum Qt::WindowType>(int * __formal) Line 112 C++
SideBySideRenderWindowsQt.exe!Ui_SideBySideRenderWindowsQt::setupUi(QMainWindow * SideBySideRenderWindowsQt) Line 72 C++
SideBySideRenderWindowsQt.exe!SideBySideRenderWindowsQt::SideBySideRenderWindowsQt() Line 19 C++
SideBySideRenderWindowsQt.exe!main(int argc, char * * argv) Line 9 C++
EDIT 2: Example
This example is from generating a new project of type QT GUI Application in Visual Studio 2013
See the comments in ui_QtGuiApplication.h
main.cpp
#include "QtGuiApplication2.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtGuiApplication2 w;
w.show();
return a.exec();
}
QtGuiApplication2.h
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication2.h"
class QtGuiApplication2 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication2(QWidget *parent = Q_NULLPTR);
private:
Ui::QtGuiApplication2Class ui;
};
QtGuiApplication2.cpp
#include "QtGuiApplication2.h"
QtGuiApplication2::QtGuiApplication2(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
ui_QtGuiApplication.h
This file is generated after using QT Design via Visual Studio:
#ifndef UI_QTGUIAPPLICATION2_H
#define UI_QTGUIAPPLICATION2_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_QtGuiApplication2Class
{
public:
QWidget *centralWidget;
QVTKWidget *qvtkWidget; //Generated after adding VTK Widget
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *QtGuiApplication2Class)
{
if (QtGuiApplication2Class->objectName().isEmpty())
QtGuiApplication2Class->setObjectName(QStringLiteral("QtGuiApplication2Class"));
QtGuiApplication2Class->resize(600, 400);
centralWidget = new QWidget(QtGuiApplication2Class);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
//THE LINES BELOW ARE GENERATED IF I
//ADD A VTK WIDGET FROM QT DESIGN:
//In Debug mode, the first line returns:
//The program '[15392] QtGuiApplication2.exe' has exited with code 1 (0x1).
//In Release mode, the program works fine.
qvtkWidget = new QVTKWidget(centralWidget);
qvtkWidget->setObjectName(QStringLiteral("qvtkWidget"));
qvtkWidget->setGeometry(QRect(200, 100, 100, 100));
QtGuiApplication2Class->setCentralWidget(centralWidget);
menuBar = new QMenuBar(QtGuiApplication2Class);
menuBar->setObjectName(QStringLiteral("menuBar"));
menuBar->setGeometry(QRect(0, 0, 600, 21));
QtGuiApplication2Class->setMenuBar(menuBar);
mainToolBar = new QToolBar(QtGuiApplication2Class);
mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
QtGuiApplication2Class->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(QtGuiApplication2Class);
statusBar->setObjectName(QStringLiteral("statusBar"));
QtGuiApplication2Class->setStatusBar(statusBar);
retranslateUi(QtGuiApplication2Class);
QMetaObject::connectSlotsByName(QtGuiApplication2Class);
} // setupUi
void retranslateUi(QMainWindow *QtGuiApplication2Class)
{
QtGuiApplication2Class->setWindowTitle(QApplication::translate("QtGuiApplication2Class", "QtGuiApplication2", 0));
} // retranslateUi
};
namespace Ui {
class QtGuiApplication2Class: public Ui_QtGuiApplication2Class {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_QTGUIAPPLICATION2_H
Upvotes: 2
Views: 1287
Reputation: 1047
Answer to my own problem
As I already had built VTK in both Debug and Release mode I thought that was in order.
But I saw in the output that my solution was getting the dll files from ...\VTK\VTK-bin\bin\Release\
which was added in Environment variables as a PATH
.
I solved this by also adding ...\VTK\VTK-bin\bin\Debug\
.
In environment variables under the PATH
i know have:
C:\VTK\VTK-bin\bin\Debug
C:\VTK\VTK-bin\bin\Release
As Debug is listed first, it will get the dlls from this folder now, and I can correctly run in debug mode. (Atm the moment I need to switch the order of these two variables if I want to build in Release mode, so would still have to find a better solution for how the project finds the dlls.)
An additional problem that happened for me was a new error, it is described here: no override found for 'vtkPolyDataMapper' , and as stated in the solution it was resolved by adding:
#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2, vtkInteractionStyle)
in the beginning of QVTKwidget.h
Upvotes: 1