[Visual Studio] Use Visual Studio with Qt to build VTK on Windows

Knowledge is not alone, it must be systematic. More my personal summary and related experience can be found in this column: Visual Studio .

serial number content
1 [Visual Studio] Use Visual Studio to build VTK on Windows
2 [Visual Studio] Use Visual Studio with Qt to build VTK on Windows
3 【VTK】VTK display small ball example, use Visual Studio with Qt to build VTK on Windows
4 [VTK] Official example, ported to your own Qt project, including code

I have completed the use of Visual Studio to build VTK on Windows before. This article combines the implementation of Qt to use Visual Studio with Qt to build VTK on Windows. The link to the previous article is: [Visual Studio] Use Visual Studio to build VTK on Windows .

1 version environment

  • win11
  • visual studio 2022
  • VTK-9.2.6
  • CMake 3.26.3
  • Qt 6.2.8

2 build steps

It is recommended to use the administrator identity when opening CMake and Visual Studio throughout the process to prevent unnecessary trouble. At the same time, if the computer has been installed in Visual Studio in advance Qt VS Tool, please uninstall it in advance, and it is best to restart the computer.

If you don't know how to install and uninstall Qt VS Tool, you can refer to: 【VisualStudio】Using C++ language to develop Qt environment configuration tutorial based on Visual Studio .

1 Prepare folder structure

I created a on the C drive VTKFoldersto save all the required files.

insert image description here

2 run CMake

Use CMake to generate a visual studio solution.

First open CMake-GUI as administrator. Configure the resource folder and buildfolder. Then click Configure.

insert image description here

A selection box will pop up, select the configuration that suits you, and then Finish.

I installed a 32-bit Qt 5.12.12 and a 64-bit Qt 6.2.8 on my computer. After testing Qt 5 many times, they still couldn’t work, so I chose the 64-bit Qt 6.2.8 to install. As for whether the 32-bit Qt 6 series can be used, I haven’t tested it.

The image here needs to be replaced

insert image description here

We now have several options that can be toggled on or off as needed. like:

  • Modify CMAKE_INSTALL_PREFIXto the folder you want to specify
  • Check Advanced, search qt, and select all options Yes.

insert image description here

insert image description here

Then click Configure, you can click several times until there is no red warning prompt.

At this time, Qt may not be found, because the Qt environment has not been added to the system environment variables. Qt can be added to environment variables as shown in the figure below. Note that the paths are for reference only because the respective configuration folders are different.

If you don’t know how to open the system environment variable, you can follow the tips below:
[ start -> Edit the system environment variables -> Advanced -> Environment Variables -> Path -> Edit -> New]

insert image description here
After configuring the system environment variables, restart CMake-GUI, and again Configure, you can automatically search for Qt.
Afterwards Generate, this will populate VTK-buildthe subfolder. Open ProjectEnter the Visual Studio project.

Figure needs to be replaced

insert image description here

3 Build in Visual Studio

Select Releaseand X64.
Then right click ALL_BUILD -> 生成.

insert image description here

Depending on the performance of the computer, the time it takes will vary. I used my computer for 3 minutes, and the report showed 270 successes and 2 failures. I went on and on, no problem so far.
Then we can see many files in the folder .dll.
Putting my own folder path just for reference C:\VTKFolders\VTK-build\bin\Release.

insert image description here

insert image description here

Then something went setlocalwrong. This is a typical error. I also tried several methods shared on the Internet, but none of them worked for me.

insert image description here

Try the solution below. Changed post-build event to no. Then right-click the INSTALL project and click Regenerate.

insert image description here

Although it no longer reports an error setlocal, it still doesn't work.

insert image description here

Finally, try to open the Visual Studio project as an administrator, then right-click INSTALLthe project and click Regenerate, but it still doesn't work.

In the end, I found that I don't need to worry about it, just go down.

3 Whether the test was successful

1 new construction

If all goes well, you should now be able to compile and run the C++ examples.
What I'm testing here is whether Widgetthe control can be promoted to QVTKOpenGLNativeWidgetand run successfully.

Create a new Qt project named , VTKTestdrag in a Widgetcontrol, upgrade it to QVTKOpenGLNativeWidgetand get the project interface as shown in the figure below.

If you don’t know how to improve it, Widgetyou can refer to: [Visual Studio] Qt’s real-time drawing curve function, use C++ language, and cooperate with Qt to develop serial communication interface .

insert image description here

2 project configuration

Then add Qt OpenGLWidgets.

If you don’t know how to enter this interface, please refer to: [Visual Studio] Error LNK2019, use C++ language, cooperate with Qt to develop serial communication interface or [Visual Studio] report error C1083, use C++ language, cooperate with Qt to develop serial communication interface .

insert image description here

Then add the required library files as shown in the figure below.

If you don’t know how to open this interface, you can refer to: [Visual Studio] Merge the .h .lib .dll files of the C++ project, including the entire configuration process. Bug error E1696 cannot open the source file, use C++ language, and cooperate with Qt to develop the serial communication interface .

insert image description here

insert image description here
At the same time, take a screenshot of your own Qt version. Sometimes various errors may occur due to version issues.

insert image description here

3 running results

The result after running successfully is shown in the figure below:

insert image description here

appendix

Because the configuration has been unsuccessful, I also tried to change the version of VTK in the middle. After changing to VTK-9.0.3, the result is more errors.
So in the end, I still made up my mind, just to make the version in my hand. Even after making all the mistakes in the end, it succeeded.

insert image description here
insert image description here


Ref.

  1. VTK and QT source code compilation and examples
  2. The latest configuration method of QT5+VTK9.1

Usage of QVTKOpenGLNativeWidget in Qt

My first VTK program - drawing a sphere

VTK reads the 3D point coordinates in a TXT file and displays the 3D point cloud

VTK draws a sphere centered on batch 3D point coordinates (point cloud), which can be used to identify feature points or chemical molecules


VTK configuration.md

The new version of VTK v9.0 cannot find the QVTKWidget.h header file? What about Qt Designer?

おすすめ

転載: blog.csdn.net/weixin_36815313/article/details/131693472