Knowledge is not alone, it must be systematic. More my personal summary and related experience can be found in this column: Visual Studio .
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 .
Article Directory
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 VTKFolders
to save all the required files.
2 run CMake
Use CMake to generate a visual studio solution.
First open CMake-GUI as administrator. Configure the resource folder and build
folder. Then click Configure
.
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
We now have several options that can be toggled on or off as needed. like:
- Modify
CMAKE_INSTALL_PREFIX
to the folder you want to specify - Check
Advanced
, searchqt
, and select all optionsYes
.
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
]
After configuring the system environment variables, restart CMake-GUI, and again Configure
, you can automatically search for Qt.
Afterwards Generate
, this will populate VTK-build
the subfolder. Open Project
Enter the Visual Studio project.
Figure needs to be replaced
3 Build in Visual Studio
Select Release
and X64
.
Then right click ALL_BUILD -> 生成
.
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
.
Then something went setlocal
wrong. This is a typical error. I also tried several methods shared on the Internet, but none of them worked for me.
Try the solution below. Changed post-build event to no. Then right-click the INSTALL project and click Regenerate.
Although it no longer reports an error setlocal
, it still doesn't work.
Finally, try to open the Visual Studio project as an administrator, then right-click INSTALL
the 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 Widget
the control can be promoted to QVTKOpenGLNativeWidget
and run successfully.
Create a new Qt project named , VTKTest
drag in a Widget
control, upgrade it to QVTKOpenGLNativeWidget
and get the project interface as shown in the figure below.
If you don’t know how to improve it, Widget
you can refer to: [Visual Studio] Qt’s real-time drawing curve function, use C++ language, and cooperate with Qt to develop serial communication interface .
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 .
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 .
At the same time, take a screenshot of your own Qt version. Sometimes various errors may occur due to version issues.
3 running results
The result after running successfully is shown in the figure below:
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.
Ref.
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
The new version of VTK v9.0 cannot find the QVTKWidget.h header file? What about Qt Designer?