Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. How can I connect my QT cmake project to LibXL
QtWS25 Last Chance

How can I connect my QT cmake project to LibXL

Scheduled Pinned Locked Moved Unsolved Qt 6
9 Posts 3 Posters 636 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mihil Ranasinghe
    wrote on 3 Jun 2024, 10:57 last edited by
    #1

    I am making an project and I need the LibXL library for modifying excel sheets.
    I tried some ways to connect the library to the project

    cmake_minimum_required(VERSION 3.5)
    
    project(TM_Checker VERSION 0.1 LANGUAGES CXX)
    
    # Enable automatic Qt features
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    # Set the C++ standard
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    # Find Qt package
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Sql)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Sql)
    
    # Project source files
    set(PROJECT_SOURCES
        TMCheckerDoc.h
        TMCheckerDoc.cpp
        main.cpp
        mainwindow.cpp
        dialogbrowsefiles.cpp
        dialogbrowsefiles.h
        mainwindow.h
        mainwindow.ui
        dialogbrowsefiles.ui
    )
    
    # Add executable for different Qt versions and platforms
    if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
        qt_add_executable(TM_Checker
            MANUAL_FINALIZATION
            ${PROJECT_SOURCES}
        )
    else()
        if(ANDROID)
            add_library(TM_Checker SHARED
                ${PROJECT_SOURCES}
            )
            set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
        else()
            add_executable(TM_Checker
                ${PROJECT_SOURCES}
            )
        endif()
    endif()
    
    # Set target properties
    set_target_properties(TM_Checker PROPERTIES
        MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    # Install rules
    install(TARGETS TM_Checker
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    
    # Include libxl
    if(NOT DEFINED LIBXL_HEADERPATH)
        # set(LIBXL_HEADERPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl/include/)
        set(LIBXL_HEADERPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl-4.3.0.14/include_cpp/)
    endif()
    
    if(NOT DEFINED LIBXL_LIBPATH)
        # set(LIBXL_LIBPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl/lib/)
        set(LIBXL_LIBPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl-4.3.0.14/lib/)
    endif()
    
    target_include_directories(TM_Checker
        PRIVATE
            ${LIBXL_HEADERPATH}
        PUBLIC
            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/header>
            $<INSTALL_INTERFACE:include/libxlQt${QT_VERSION_MAJOR}>
    )
    
    # Link libxl and Qt libraries
    link_directories(${LIBXL_LIBPATH})
    
    target_link_libraries(TM_Checker PRIVATE
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Sql
        xl
    )
    
    # Finalize executable for Qt 6
    if(QT_VERSION_MAJOR EQUAL 6)
        qt_finalize_executable(TM_Checker)
    endif()
    
    

    above is the code but it won't make it display in the projects tab even though there is no issue.
    Help me with this issue please.

    J 1 Reply Last reply 3 Jun 2024, 11:59
    0
    • M Mihil Ranasinghe
      3 Jun 2024, 10:57

      I am making an project and I need the LibXL library for modifying excel sheets.
      I tried some ways to connect the library to the project

      cmake_minimum_required(VERSION 3.5)
      
      project(TM_Checker VERSION 0.1 LANGUAGES CXX)
      
      # Enable automatic Qt features
      set(CMAKE_AUTOUIC ON)
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      
      # Set the C++ standard
      set(CMAKE_CXX_STANDARD 17)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      # Find Qt package
      find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Sql)
      find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Sql)
      
      # Project source files
      set(PROJECT_SOURCES
          TMCheckerDoc.h
          TMCheckerDoc.cpp
          main.cpp
          mainwindow.cpp
          dialogbrowsefiles.cpp
          dialogbrowsefiles.h
          mainwindow.h
          mainwindow.ui
          dialogbrowsefiles.ui
      )
      
      # Add executable for different Qt versions and platforms
      if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
          qt_add_executable(TM_Checker
              MANUAL_FINALIZATION
              ${PROJECT_SOURCES}
          )
      else()
          if(ANDROID)
              add_library(TM_Checker SHARED
                  ${PROJECT_SOURCES}
              )
              set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
          else()
              add_executable(TM_Checker
                  ${PROJECT_SOURCES}
              )
          endif()
      endif()
      
      # Set target properties
      set_target_properties(TM_Checker PROPERTIES
          MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
          MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
          MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
          MACOSX_BUNDLE TRUE
          WIN32_EXECUTABLE TRUE
      )
      
      # Install rules
      install(TARGETS TM_Checker
          BUNDLE DESTINATION .
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
      )
      
      # Include libxl
      if(NOT DEFINED LIBXL_HEADERPATH)
          # set(LIBXL_HEADERPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl/include/)
          set(LIBXL_HEADERPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl-4.3.0.14/include_cpp/)
      endif()
      
      if(NOT DEFINED LIBXL_LIBPATH)
          # set(LIBXL_LIBPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl/lib/)
          set(LIBXL_LIBPATH ${CMAKE_CURRENT_SOURCE_DIR}/libxl-4.3.0.14/lib/)
      endif()
      
      target_include_directories(TM_Checker
          PRIVATE
              ${LIBXL_HEADERPATH}
          PUBLIC
              $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/header>
              $<INSTALL_INTERFACE:include/libxlQt${QT_VERSION_MAJOR}>
      )
      
      # Link libxl and Qt libraries
      link_directories(${LIBXL_LIBPATH})
      
      target_link_libraries(TM_Checker PRIVATE
          Qt${QT_VERSION_MAJOR}::Widgets
          Qt${QT_VERSION_MAJOR}::Sql
          xl
      )
      
      # Finalize executable for Qt 6
      if(QT_VERSION_MAJOR EQUAL 6)
          qt_finalize_executable(TM_Checker)
      endif()
      
      

      above is the code but it won't make it display in the projects tab even though there is no issue.
      Help me with this issue please.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 3 Jun 2024, 11:59 last edited by
      #2

      @Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:

      but it won't make it display in the projects tab

      What do you mean by that?
      Does ${CMAKE_CURRENT_SOURCE_DIR}/libxl-4.3.0.14/lib contain the library file?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 4 Jun 2024, 04:20
      1
      • J jsulm
        3 Jun 2024, 11:59

        @Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:

        but it won't make it display in the projects tab

        What do you mean by that?
        Does ${CMAKE_CURRENT_SOURCE_DIR}/libxl-4.3.0.14/lib contain the library file?

        M Offline
        M Offline
        Mihil Ranasinghe
        wrote on 4 Jun 2024, 04:20 last edited by
        #3

        @jsulm said in How can I connect my QT cmake project to LibXL:

        What do you mean by that?

        bd38a26d-d5c0-4df8-8260-c58a9a607992-image.png
        The library not being displayed.

        C J 2 Replies Last reply 4 Jun 2024, 04:47
        0
        • M Mihil Ranasinghe
          4 Jun 2024, 04:20

          @jsulm said in How can I connect my QT cmake project to LibXL:

          What do you mean by that?

          bd38a26d-d5c0-4df8-8260-c58a9a607992-image.png
          The library not being displayed.

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 4 Jun 2024, 04:47 last edited by
          #4

          @Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:

          The library not being displayed

          Why should libraries linked to the project should be shown in the project tree? Do you see QtWidgets lib in there? They are not shown there.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          M 1 Reply Last reply 4 Jun 2024, 06:14
          0
          • M Mihil Ranasinghe
            4 Jun 2024, 04:20

            @jsulm said in How can I connect my QT cmake project to LibXL:

            What do you mean by that?

            bd38a26d-d5c0-4df8-8260-c58a9a607992-image.png
            The library not being displayed.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 4 Jun 2024, 05:08 last edited by
            #5

            @Mihil-Ranasinghe You either build the library and add it to your project like any other shared library (using target_link_libraries) or you add the library source code to your project.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • C Christian Ehrlicher
              4 Jun 2024, 04:47

              @Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:

              The library not being displayed

              Why should libraries linked to the project should be shown in the project tree? Do you see QtWidgets lib in there? They are not shown there.

              M Offline
              M Offline
              Mihil Ranasinghe
              wrote on 4 Jun 2024, 06:14 last edited by
              #6

              @Christian-Ehrlicher Because LibXL is a external library, I am saying this because when I was using QXlsx library it was shown in project tree.
              9ed1d6b9-e927-4b5d-b7a6-a1e837c906f9-image.png
              like this.

              J C 2 Replies Last reply 4 Jun 2024, 06:15
              0
              • M Mihil Ranasinghe
                4 Jun 2024, 06:14

                @Christian-Ehrlicher Because LibXL is a external library, I am saying this because when I was using QXlsx library it was shown in project tree.
                9ed1d6b9-e927-4b5d-b7a6-a1e837c906f9-image.png
                like this.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 4 Jun 2024, 06:15 last edited by
                #7

                @Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:

                Because LibXL is a external library

                Then link it properly using target_link_libraries

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                M 1 Reply Last reply 4 Jun 2024, 06:42
                1
                • J jsulm
                  4 Jun 2024, 06:15

                  @Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:

                  Because LibXL is a external library

                  Then link it properly using target_link_libraries

                  M Offline
                  M Offline
                  Mihil Ranasinghe
                  wrote on 4 Jun 2024, 06:42 last edited by
                  #8

                  @jsulm OK thanks a lot. I think I found the issue.
                  The thing is I guess it has been recognised and loaded. It's not displayed in the project tree is because LibXL(https://www.libxl.com/download.html) does not contain a CMakeList.txt in it.

                  Anyways thanks alot @jsulm 🙏

                  1 Reply Last reply
                  0
                  • M Mihil Ranasinghe
                    4 Jun 2024, 06:14

                    @Christian-Ehrlicher Because LibXL is a external library, I am saying this because when I was using QXlsx library it was shown in project tree.
                    9ed1d6b9-e927-4b5d-b7a6-a1e837c906f9-image.png
                    like this.

                    C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 4 Jun 2024, 06:53 last edited by
                    #9

                    @Mihil-Ranasinghe said in How can I connect my QT cmake project to LibXL:

                    was using QXlsx library it was shown in project tree.

                    You did not - you just added the sources to your project instead linking to an external library - these are two completely different things.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    1

                    2/9

                    3 Jun 2024, 11:59

                    topic:navigator.unread, 7
                    • Login

                    • Login or register to search.
                    2 out of 9
                    • First post
                      2/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved