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. VisualStudio - new QObject Class
QtWS25 Last Chance

VisualStudio - new QObject Class

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 303 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.
  • P Offline
    P Offline
    Pfanne
    wrote on last edited by
    #1

    Hi,

    I try to implement a new Class based on QObject.

    Implementing a simple header [IEC104.h] an cpp [IEC104.cpp] with non QObjekt workes fine.

    [IEC104.h]

    #include <QObject>
    #include <QTcpSocket>
    
    class IEC104_Server //: public QObject
    {
        //Q_OBJECT
    
    public:
        //IEC104_Server(QObject* parent = 0);
    
        void start();
    
    private:
        //QTcpSocket* soc;
    };
    

    [IEC104.cpp]

    #include <IEC104.h>
    
    //IEC104_Server::IEC104_Server(QObject* parent) :
    //    QObject(parent)
    //{
    //    soc = new QTcpSocket(this);
    //}
    
    void IEC104_Server::start() {
        qDebug() << "--------------------------------------------------------";
        qDebug() << "[IEC104_Server::start()]";
    
    }
    

    Also my other QObjects in other files and classes are working fine.

    Enabeling the inheritance on QObject:
    [IEC104.h]

    #include <QObject>
    #include <QTcpSocket>
    
    class IEC104_Server : public QObject
    {
        Q_OBJECT
    
    public:
        IEC104_Server(QObject* parent = 0);
    
        void start();
    
    private:
        QTcpSocket* soc;
    };
    

    [IEC104.cpp]

    #include <IEC104.h>
    
    IEC104_Server::IEC104_Server(QObject* parent) :
        QObject(parent)
    {
        soc = new QTcpSocket(this);
    }
    
    void IEC104_Server::start() {
        qDebug() << "--------------------------------------------------------";
        qDebug() << "[IEC104_Server::start()]";
    
    }
    

    This throws the following compiler errors;

    Die Erstellung wurde um 13:38 gestartet...
    1>------ Erstellen gestartet: Projekt: MY_PROJECT, Konfiguration: Release x64 ------
    1>Automatic MOC and UIC for target MY_PROJECT
    1>IEC104.cpp
    1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
    1>mocs_compilation_Release.cpp
    1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
    1>main.cpp
    1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
    1>mainwindow.cpp
    1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
    1>Code wird generiert...
    1>IEC104.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual struct QMetaObject const * __cdecl IEC104_Server::metaObject(void)const " (?metaObject@IEC104_Server@@UEBAPEBUQMetaObject@@XZ)".
    1>IEC104.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual void * __cdecl IEC104_Server::qt_metacast(char const *)" (?qt_metacast@IEC104_Server@@UEAAPEAXPEBD@Z)".
    1>IEC104.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual int __cdecl IEC104_Server::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@IEC104_Server@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)".
    1>C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\build\Release\MY_PROJECT.exe : fatal error LNK1120: 3 nicht aufgelöste Externe
    1>Die Erstellung des Projekts "MY_PROJECT.vcxproj" ist abgeschlossen -- FEHLER.
    ========== Build: 0 erfolgreich, 1 Fehler, 1 aktuell, 0 übersprungen ==========
    ========== Erstellen abgeschlossen um 13:38 und dauerte 15,062 Sekunden ==========
    

    What´s wrong with it?

    1 Reply Last reply
    0
    • JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      These are not compilation errors, they are linker errors.
      Every time you add in or take out Q_OBJECT macro you should recompile & link everything completely from scratch. Best is to delete the build output folder (not the source folder) so you know it's clean. Try that and see what happens with your error message.

      1 Reply Last reply
      2
      • P Offline
        P Offline
        Pfanne
        wrote on last edited by
        #3

        yes, linker erros, of course....

        I deleted my *.obj release folder...
        C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\build\MY_PROJECT.dir\Release
        So all files should be new compiled, was that enough?

        The linker error is still present....

        Die Erstellung wurde um 19:59 gestartet...
        1>------ Erstellen gestartet: Projekt: ZERO_CHECK, Konfiguration: Release x64 ------
        1>Checking Build System
        2>------ Erstellen gestartet: Projekt: MY_PROJECT, Konfiguration: Release x64 ------
        2>Automatic MOC and UIC for target MY_PROJECT
        2>AutoMoc: C:/TEMP/Code/IEC61850_Qt/examples/QtWidgets/Qt6CMake-main/include/helper.h(0:1): note: No relevant classes found. No output generated.
        2>Building Custom Rule C:/TEMP/Code/IEC61850_Qt/examples/QtWidgets/Qt6CMake-main/CMakeLists.txt
        2>IEC104.cpp
        2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
        2>mocs_compilation_Release.cpp
        2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
        2>helper.cpp
        2>iec61850_control.cpp
        2>main.cpp
        2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
        2>mainwindow.cpp
        2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
        2>sitipe_master.cpp
        2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
        2>C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\src\sitipe_master.cpp(386,13): warning C4551: Dem Funktionsaufruf fehlt die Argumentliste
        2>Code wird generiert...
        2>mainwindow.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual struct QMetaObject const * __cdecl IEC104_Server::metaObject(void)const " (?metaObject@IEC104_Server@@UEBAPEBUQMetaObject@@XZ)".
        2>mainwindow.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual void * __cdecl IEC104_Server::qt_metacast(char const *)" (?qt_metacast@IEC104_Server@@UEAAPEAXPEBD@Z)".
        2>mainwindow.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual int __cdecl IEC104_Server::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@IEC104_Server@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)".
        2>C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\build\Release\MY_PROJECT.exe : fatal error LNK1120: 3 nicht aufgelöste Externe
        2>Die Erstellung des Projekts "MY_PROJECT.vcxproj" ist abgeschlossen -- FEHLER.
        ========== Build: 1 erfolgreich, 1 Fehler, 0 aktuell, 0 übersprungen ==========
        ========== Erstellen abgeschlossen um 20:00 und dauerte 22,130 Sekunden ==========
        
        
        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you have CMAKE_AUTOMOC enabled in the CMakeLists.txt? Please post it.

          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
          • P Offline
            P Offline
            Pfanne
            wrote on last edited by
            #5

            in file "mocs_compilation_Release.cpp" my source is missing...

            // This file is autogenerated. Changes will be overwritten.
            #include <6YEA5652QU/moc_helper.cpp>
            #include <6YEA5652QU/moc_mainwindow.cpp>
            #include <6YEA5652QU/moc_sitipe_master.cpp>
            
            
            cmake_minimum_required(VERSION 3.14)
            
            if (WIN32)
                project(MY_PROJECT LANGUAGES CXX)
            elseif(UNIX)
                project(MY_PROJECT)
            endif()
            
            set(CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo" CACHE STRING "" FORCE)
            
            #======================= INCLUSION OF Qt =======================#
            set(CMAKE_INCLUDE_CURRENT_DIR ON)
            set(CMAKE_AUTOMOC ON)
            set(CMAKE_AUTOUIC ON)
            set(CMAKE_PREFIX_PATH $ENV{QTDIR})
            find_package(Qt6Core REQUIRED)
            find_package(Qt6Widgets REQUIRED)
            find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
            
            #find_package(libiec61850 REQUIRED)
            message("found!!")
            
            #=================== INCLUSION OF Project Files ====================#
            set(FORMS_DIR "${CMAKE_SOURCE_DIR}/forms")
            set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
            set(SOURCE_DIR "${CMAKE_SOURCE_DIR}/src")
            set(IEC61850_INCLUDE_DIR "C:/Program Files/libiec61850/include/libiec61850")
            set(LIB_DIR "C:/Program Files/libiec61850/lib")
            #set(IEC61850_INCLUDE_DIR "T:/Coding/repos/libs/iec61850/include/libiec61850")
            #set(LIB_DIR "T:/Coding/repos/libs/iec61850/lib")
            
            include_directories(${FORMS_DIR})
            include_directories(${INCLUDE_DIR})
            include_directories(${SOURCE_DIR})
            
            
            
            file(GLOB_RECURSE SOURCES
                "${FORMS_DIR}/*.ui"
                "${FORMS_DIR}/*.qrc"
                "${INCLUDE_DIR}/*.h"
                "${SOURCE_DIR}/*.cpp"
                "${IEC61850_INCLUDE_DIR}/*.h"
            )
            
            #=================== SETUP EXECTUABLE ====================#
            # Enable debug logging on RELWITHDEBINFO configuration
            set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
                $<$<CONFIG:RELWITHDEBINFO>:QT_MESSAGELOGCONTEXT>
            )
            
            # Add the forms directory to the AUTOUIC search paths
            set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_AUTOUIC_SEARCH_PATHS} ${FORMS_DIR})
            
            # Add the executable
            if (WIN32) 
                add_executable(MY_PROJECT WIN32 ${SOURCES})
            elseif(UNIX)
                add_executable(MY_PROJECT ${SOURCES})
            endif()
            
            # Add the target includes for MY_PROJECT 
            target_include_directories(MY_PROJECT PRIVATE ${FORMS_DIR})
            target_include_directories(MY_PROJECT PRIVATE ${INCLUDE_DIR})
            target_include_directories(MY_PROJECT PRIVATE ${SOURCE_DIR})
            target_include_directories(MY_PROJECT PRIVATE ${IEC61850_INCLUDE_DIR})
            
            #===================== LINKING LIBRARIES =======================#
            target_link_libraries(MY_PROJECT ${LIB_DIR}/iec61850.lib )
            target_link_libraries(MY_PROJECT ${LIB_DIR}/hal.lib )
            #target_link_libraries(MY_PROJECT ${LIB_DIR}/hal-shared.lib )
            target_link_libraries(MY_PROJECT 
                Qt6::Widgets
                Qt6::Core
                Qt6::Gui
                Qt6::Network
                Qt6::Widgets
            )
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Globbing... cmake should deprecate this.
              Please re-run cmake so the new header file is found or remove the globbing and write all files directly into the CMakeLists.txt

              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
              • P Offline
                P Offline
                Pfanne
                wrote on last edited by Pfanne
                #7

                after deleting the build dir an run cmake the "mocs_compilation_Release.cpp" contains my "IEC104.cpp"

                // This file is autogenerated. Changes will be overwritten.
                #include <6YEA5652QU/moc_IEC104.cpp>
                #include <6YEA5652QU/moc_mainwindow.cpp>
                #include <6YEA5652QU/moc_sitipe_master.cpp>
                
                

                now this error is left...

                Schweregrad	Code	Beschreibung	Projekt	Datei	Zeile	Unterdrückungszustand	Details
                Fehler	C2011	"IEC104_Server": "class" Typneudefinition	MY_PROJECT	C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\include\IEC104.h	25		
                Fehler	C2079	"MainWindow::iec104" verwendet undefiniertes class "IEC104_Server"	MY_PROJECT	C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\include\mainwindow.h	89		
                
                
                Die Erstellung wurde um 21:41 gestartet...
                1>------ Erstellen gestartet: Projekt: ZERO_CHECK, Konfiguration: Release x64 ------
                1>Checking Build System
                2>------ Erstellen gestartet: Projekt: MY_PROJECT, Konfiguration: Release x64 ------
                2>Automatic MOC and UIC for target MY_PROJECT
                2>Building Custom Rule C:/TEMP/Code/IEC61850_Qt/examples/QtWidgets/Qt6CMake-main/CMakeLists.txt
                2>mocs_compilation_Release.cpp
                2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
                2>C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\include\IEC104.h(25,21): error C2011: "IEC104_Server": "class" Typneudefinition
                2>(Quelldatei „MY_PROJECT_autogen/mocs_compilation_Release.cpp“ wird kompiliert)
                2>C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\include\IEC104.h(25,7):
                2>Siehe Deklaration von "IEC104_Server"
                2>C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\include\mainwindow.h(88,19): error C2079: "MainWindow::iec104" verwendet undefiniertes class "IEC104_Server"
                2>(Quelldatei „MY_PROJECT_autogen/mocs_compilation_Release.cpp“ wird kompiliert)
                2>IEC104.cpp
                2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
                2>helper.cpp
                2>iec61850_control.cpp
                2>main.cpp
                2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
                2>mainwindow.cpp
                2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
                2>sitipe_master.cpp
                2>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\format(42): warning STL4038: The contents of <format> are available only with C++20 or later.
                2>C:\TEMP\Code\IEC61850_Qt\examples\QtWidgets\Qt6CMake-main\src\sitipe_master.cpp(386,13): warning C4551: Dem Funktionsaufruf fehlt die Argumentliste
                2>Code wird generiert...
                2>Die Erstellung des Projekts "MY_PROJECT.vcxproj" ist abgeschlossen -- FEHLER.
                ========== Build: 1 erfolgreich, 1 Fehler, 0 aktuell, 0 übersprungen ==========
                ========== Erstellen abgeschlossen um 21:42 und dauerte 20,284 Sekunden ==========
                
                
                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Pfanne
                  wrote on last edited by
                  #8

                  OK, setting compiler switches helped!!

                  #ifndef IEC104_Server_H
                  #define IEC104_Server_H
                  
                  //#############################################################################
                  // TCP Socket
                  //#############################################################################
                  
                  class IEC104_Server : public QObject
                  {
                      Q_OBJECT
                  
                  public:
                      explicit IEC104_Server(QObject* parent = 0);
                  
                  1 Reply Last reply
                  1
                  • P Pfanne has marked this topic as solved on

                  • Login

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