Work with Word Documents in Qt

Qt is a C++ based cross-platform application development framework which is widely used to develop a variety of desktop, mobile, and embedded system applications. Aspose.Words for C++ can be integrated within Qt in order to create and manipulate Word documents in your Qt applications. You can find complete Qt example at GitHub

Using Aspose.Words for C++ within Qt Creator

For using Aspose.Words for C++ in your Qt application download the latest version of the API from the downloads section. Once the API is downloaded, you can use integrate the C++ library within Qt Creator or you can use with Visual Studio.

In order to integrate and use Aspose.Words for C++ library within a Qt Console Application developed in Qt Creator, please follow the steps given below:

  • Open Qt Creator and create a new Qt Console Application

  • Select the QMake option from the Build System dropdown

  • Select the appropriate kit and finish the wizard.

  • Copy Aspose.Words.Cpp and CodePorting.Native.Cs2Cpp folders from the extracted package of Aspose.Words for C++ into the root of the project

  • In order to add paths to lib and include folders, right-click on the project in the LHS panel and select Add Library

  • Select the External Library option and browse paths to include and lib folders one by one

  • Once done, your .pro project file will contain the following entries

  • Build the application and you are done with the integration

  • Select the External Library option and browse paths to include and lib folders one by one

  • Once done, your .pro project file will contain the following entries

  • Build the application and you are done with the integration

Using Aspose.Words for C++ in Qt Applications within Visual Studio

For developing a Qt application using Visual Studio, you require to install Qt Visual Studio Tools. Once you have the installation, download the latest version of the API from the downloads section and follow the steps given below:

  • Download and install CMake.
  • Download and unpack Aspose.Words for C++.
  • Create a new folder for your project files and copy/paste Aspose.Words.Cpp and CodePorting.Native.Cs2Cpp folders from unpacked package.
  • Create a new file named CMakeLists.txt in the same folder.
  • Copy and paste the following content within the CMakeLists.txt file.
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(Qt_AsposeWords_CMake)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(CodePorting.Native.Cs2Cpp REQUIRED CONFIG PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
find_package(Aspose.Words.Cpp REQUIRED CONFIG PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
add_executable(Qt_AsposeWords_CMake
    main.cpp
)
target_link_libraries(Qt_AsposeWords_CMake PRIVATE Qt5::Widgets Aspose::Words) 
set_directory_properties(PROPERTIES VS_STARTUP_PROJECT Qt_AsposeWords_CMake)
file(TO_NATIVE_PATH "${Aspose.Words.Cpp_DIR}/lib/${CMAKE_VS_PLATFORM_NAME}" Aspose.Words.Cpp_DLL_PATH)
file(TO_NATIVE_PATH "${CodePorting.Native.Cs2Cpp_DIR}/lib" CodePorting.Native.Cs2Cpp_DLL_PATH)
file(TO_NATIVE_PATH "${Qt5_DIR}/../../../bin" Qt5_DLL_PATH)
set_target_properties(Qt_AsposeWords_CMake PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=${Aspose.Words.Cpp_DLL_PATH}\\$<CONFIG>;${CodePorting.Native.Cs2Cpp_DLL_PATH};${Qt5_DLL_PATH};$(Path)")
  • Open Command Prompt and cd to the project folder.
  • Run the following command by replacing  with the path to Qt5Config.cmake file.
cmake -G "Visual Studio 17 2022" -Thost=x64 -Ax64 -S . -B build -D"Qt5_DIR=<path-to-qt5>"
  • Once you have completed the above-mentioned steps, a Visual Studio solution will be created in the folder. You are now ready to use Aspose.Words for C++ features within the Qt application.