Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Migrating from Qt4 to Qt5 issues
Qt 6.11 is out! See what's new in the release blog

Migrating from Qt4 to Qt5 issues

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 807 Views 2 Watching
  • 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.
  • D Offline
    D Offline
    djsuson
    wrote on last edited by
    #1

    I know there have been a number of posts regarding migrating code from Qt4 to Qt5, but none of the answers provided are working for me. I have a project that is built in KDevelop, which uses a cmake build system by default. The older project uses cmake and I'm not in a position to switch away from it.

    My problem is that I am getting is that my include commands, such as

    #include <QtWidgets>
    

    come back with a 'QtWidgets' file not found error. My CMakeLists.txt file is

    project(q5analyzer)
    
    cmake_minimum_required(VERSION 3.10)
    
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    set(CMAKE_AUTOUIC ON)
    
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../../cmake/Modules/")
    
    find_package(Qt5 COMPONENTS Core Widgets Gui REQUIRED)
    # find_package(CFitsio REQUIRED)
    find_package(CCfits REQUIRED)
    # find_package(GSL REQUIRED)
    find_package(GOMP REQUIRED)
    find_package(HealPIX REQUIRED)
    
    set(qcanalyzer_SRCS
        main.cpp
        mainwindow.cpp
        controldatadlg.cpp
        mapperdlg.cpp
        mapselectdlg.cpp
        graphdlg.cpp
        graphselectdlg.cpp
        pixelizerdlg.cpp
        healpixdlg.cpp
        transformerdlg.cpp
        rshtdlg.cpp
        spectrumdlg.cpp)
    set(qcanalyzer_MOC_HDRS
        mainwindow.h
        controldatadlg.h
        mapperdlg.h
        mapselectdlg.h
        graphdlg.h
        graphselectdlg.h
        pixelizerdlg.h
        healpixdlg.h
        transformerdlg.h
        rshtdlg.h
        spectrumdlg.h)
    set(qcanalyzer_UIS
        mainwindow.ui
        controldatadlg.ui
        mapperdlg.ui
        mapselectdlg.ui
        graphdlg.ui
        graphselectdlg.ui
        pixelizerdlg.ui
        healpixdlg.ui
        transformerdlg.ui
        rshtdlg.ui
        spectrumdlg.ui)
    set(qcanalyzer_RCS
        mainwindow.qrc)
         
    qt_add_resources(qcanalyzer_RC_SRCS ${qcanalyzer_RCS})
    qt_wrap_ui(qcanalyzer_UI_HDRS ${qcanalyzer_UIS})
    qt_wrap_cpp(qcanalyzer_MOC_SRCS ${qcanalyzer_MOC_HDRS})
    
    include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/..)
    link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../libanalyzer/ ${CMAKE_CURRENT_BINARY_DIR}/../../libgraphics/)
    
    add_executable(q5analyzer ${qcanalyzer_SRCS} ${qcanalyzer_MOC_SRCS} ${qcanalyzer_UI_HDRS} ${qcanalyzer_RC_SRCS})
    
    target_link_libraries(q5analyzer ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} graphics analyzer ${GOMP_LIBRARIES} ${HEALPIX_LIBRARIES} ${CCFITS_LIBRARIES} ${CFITSIO_LIBRARIES} ${GSL_LIBRARIES})
    # install(TARGETS qcanalyzer RUNTIME DESTINATION bin)
    
    

    What do I need to do so that the header files are found and I can build the program?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You are not linking to the widgets module.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • D Offline
        D Offline
        djsuson
        wrote on last edited by
        #3

        I assume your talking about either the add_executable and/or target_link_libraries line? While I agree that this needs to be fixed, would it be causing the headers to not be found so that I can't even compile the project?

        Christian EhrlicherC 1 Reply Last reply
        0
        • D djsuson

          I assume your talking about either the add_executable and/or target_link_libraries line? While I agree that this needs to be fixed, would it be causing the headers to not be found so that I can't even compile the project?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Why not simply add Qt5::QtCore to target_link_libraries and try it out. After that you can read about imported targets and what advantage they have - it's not just linking against the lib.

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

          D 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Why not simply add Qt5::QtCore to target_link_libraries and try it out. After that you can read about imported targets and what advantage they have - it's not just linking against the lib.

            D Offline
            D Offline
            djsuson
            wrote on last edited by
            #5

            @Christian-Ehrlicher I modified the target_link_libraries to include QtCore. The line now reads

            target_link_libraries(q5analyzer Qt5::QtCore graphics analyzer ${GOMP_LIBRARIES} ${HEALPIX_LIBRARIES} ${CCFITS_LIBRARIES} ${CFITSIO_LIBRARIES} ${GSL_LIBRARIES})
            

            However, when kdevelop processes it, I get the following error

            Target "q5analyzer" links to target "Qt5::QtCore" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
            

            I was able to confirm that find_package(Qt5 COMPONENTS Core Widgets Gui REQUIRED) is finding the package, so I'm at a loss as to why I'm having these problems still.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I wrote it wrong - it's Qt5::Core as written in the documentation.

              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
              0
              • D Offline
                D Offline
                djsuson
                wrote on last edited by
                #7

                I wanted to thank you. This did indeed work. I don't understand why. In my mind, target_link_libraries is similar to the old libtool linker step. It would come at the end of the process. Why is this needed to even get the compiler to find the header files? I would have thought that the find_package is what handles that. Either way, though, I got the code to build and run, so I'm a very happy camper again!

                1 Reply Last reply
                0

                • Login

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