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. Custom QWidget (Qwt) class not found when promoted
Qt 6.11 is out! See what's new in the release blog

Custom QWidget (Qwt) class not found when promoted

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 384 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.
  • K Offline
    K Offline
    Kevin470
    wrote on last edited by
    #1

    I have a QWidget element on my ui which I would like to use for as a plotter.
    I am trying to promote it to a custom class (MyPlot) of mine which inherits QwtPlot.

    The Qwt package is found and CMake runs fine. But when I try to build it, the ui_mainwindow.h file is not finding my custom class.

    It throws the error : ui_mainwindow.h:19:10: 'src/myplot.hpp' file not found

    My CMakeLists.txt file looks like this:

    cmake_minimum_required(VERSION 3.5)
    
    project(Front VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "cmake")
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    # extend cmake module path find additional .cmake module (here in Qwt)
    set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
    
    # prepare QWT library
    set (QWT_LIBRARY "c:/cpp_libs/Qwt/Qwt-6.2.0/lib")
    set (QWT_INCLUDE_DIR "c:/cpp_libs/Qwt/Qwt-6.2.0/include")
    find_package(Qwt)
    
    if(Qwt_FOUND)
        message(STATUS "QWT Package Found")
    endif()
    
    set(PROJECT_SOURCES
            src/main.cpp
            src/mainwindow.cpp
            src/mainwindow.hpp
            src/mainwindow.ui
            src/myplot.hpp
            src/myplot.cpp
    )
    
    if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
        qt_add_executable(Front
            MANUAL_FINALIZATION
            ${PROJECT_SOURCES}
        )
    # Define target properties for Android with Qt 6 as:
    #    set_property(TARGET Front APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
    #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
    # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
    else()
        if(ANDROID)
            add_library(Front SHARED
                ${PROJECT_SOURCES}
            )
    # Define properties for Android with Qt 5 after find_package() calls as:
    #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
        else()
            add_executable(Front
                ${PROJECT_SOURCES}
            )
        endif()
    endif()
    
    # add QWT include and library directories to the project
    target_include_directories(${PROJECT_NAME} PRIVATE ${QWT_INCLUDE_DIRS})
    target_link_directories(${PROJECT_NAME} PRIVATE ${QWT_LIBRARIES})
    
    target_link_libraries(Front PUBLIC
        Qt${QT_VERSION_MAJOR}::Widgets
        qwt
    )
    
    set_target_properties(Front 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(TARGETS Front
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
    
    if(QT_VERSION_MAJOR EQUAL 6)
        qt_finalize_executable(Front)
    endif()
    
    

    My MyPlot class header looks like this:

    #ifndef MYPLOT_HPP
    #define MYPLOT_HPP
    
    #include "qwt_plot.h"
    #include "qwt_scale_engine.h"
    #include "qwt_plot_curve.h"
    #include "qwt_plot_grid.h"
    #include "qwt_scale_draw.h"
    #include "qwt_symbol.h"
    #include "qwt_legend.h"
    #include "qwt_text.h"
    #include "qwt_point_data.h"
    #include "qwt_series_data.h"
    #include "qwt_plot_zoomer.h"
    #include "qwt_plot_magnifier.h"
    
    class MyPlot : public QwtPlot
    {
        Q_OBJECT
    public:
        explicit MyPlot(QWidget *parent = nullptr);
    };
    
    #endif // MYPLOT_HPP
    

    The implementation file is just an empty constructor.

    This is the promoted classes for this widget.
    Screenshot

    What could I be missing? Thanks in advance.

    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