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. Why qt class can't be combined with some C++ source code
Qt 6.11 is out! See what's new in the release blog

Why qt class can't be combined with some C++ source code

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 653 Views 3 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.
  • stackprogramerS Offline
    stackprogramerS Offline
    stackprogramer
    wrote on last edited by stackprogramer
    #1

    I am developing some features on some open-source projects, but I observe that open source code can be compiled successfully with g++ and cmake....
    but when i import cmake project and it can compile successfully in qt....
    my problom is where that i want to add some layers that use qt classed i faced with too many strange errors.....
    for special case for srsran project when I used this section i have too many erros....How can overcome this problem in qt? This is only one problem but altogether Qt with other source cpp i faced with too many strange errors....

    can anyone guide me? Thanks in advance

    cmake section

    
    ######Custom CMake setction for creating GUI ENB
    
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    #set(CMAKE_CXX_STANDARD 20)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    # modify the actual value of the current directory's `COMPILE_OPTIONS` (copy from above line remains unchanged). subdirectories inherit a copy of their parent's `COMPILE_OPTIONS` at the time the subdirectory is processed.
    add_compile_options(-Wno-error)
    
    find_package(Qt5 COMPONENTS Widgets REQUIRED )
    
    add_executable(LTEeNB
        #main.cc
        main.cpp
        enb_layer.cpp
        enb_layer.h
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
        config_enb_layer.h
        enb_helper_functions.h
        enbthread.cpp
        enbthread.h
        ../enb.cc
        ../metrics_stdout.cc
        ../metrics_csv.cc
        ../metrics_json.cc
        ../metrics_e2.cc
        #../enb_cfg_parser.cc
      )
    
    target_link_libraries(LTEeNB PRIVATE
                                    ${SRSENB_SOURCES}
                                    ${SRSRAN_SOURCES}
                                    ${CMAKE_THREAD_LIBS_INIT}
                                    ${Boost_LIBRARIES}
                                    ${SEC_LIBRARIES}
                                    ${LIBCONFIGPP_LIBRARIES}
                                    ${SCTP_LIBRARIES}
                                    enb_cfg_parser
                                    srsran_common
                                    srsgnb_rrc_config_utils
                                    ${LIBCONFIGPP_LIBRARIES}
                                    Qt5::Widgets
    
    
      )
    

    Source Code

    #include <poll.h>
    #include <signal.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/mman.h>
    #include <unistd.h>
    
    #include "srsran/common/common_helper.h"
    #include "srsran/common/config_file.h"
    #include "srsran/common/crash_handler.h"
    #include "srsran/common/tsan_options.h"
    #include "srsran/srslog/event_trace.h"
    #include "srsran/srslog/srslog.h"
    #include "srsran/support/emergency_handlers.h"
    #include "srsran/support/signal_handler.h"
    
    #include <boost/program_options.hpp>
    #include <boost/program_options/parsers.hpp>
    #include <iostream>
    #include <memory>
    #include <srsran/common/string_helpers.h>
    #include <string>
    
    #include "srsenb/hdr/enb.h"
    #include "srsenb/hdr/metrics_csv.h"
    #include "srsenb/hdr/metrics_e2.h"
    #include "srsenb/hdr/metrics_json.h"
    #include "srsenb/hdr/metrics_stdout.h"
    #include "srsran/common/enb_events.h"
    
    
    class enb_layer
    {
      //Q_OBJECT
    public:
      //public:public:
      enb_layer();
      ~enb_layer();
      int start(int argc, char* argv[]);
      void stop();
    
    
    };
    
    

    Error:

    /...../lib/include/srsran/asn1/e2sm_kpm_v2.h:56: error: expected ‘}’ before ‘::’ token
       56 | #define None std::numeric_limits<uint32_t>::max()
          |                 ^~
    
    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      Hi @stackprogramer,

      It looks to me like the compiler is interpreting the code in e2sm_kpm_v2.h as (plane old) C, and not C++. This is probably because one of your *.cc files is including the header (either directly, or indirectly), and CMake is (again, probably) assuming your *.cc files are C (not C++).

      You could rename all *.cc files to *.cpp, or tell CMake some other way that they're all C++.

      Or if you really do need to mix C and C++ code, you will need to ensure that the C and C++ headers are also separated - eg consider using a *.hpp extension for the C++ headers.

      Hope that helps point you in the right direction.

      Cheers.

      stackprogramerS 1 Reply Last reply
      2
      • Paul ColbyP Paul Colby

        Hi @stackprogramer,

        It looks to me like the compiler is interpreting the code in e2sm_kpm_v2.h as (plane old) C, and not C++. This is probably because one of your *.cc files is including the header (either directly, or indirectly), and CMake is (again, probably) assuming your *.cc files are C (not C++).

        You could rename all *.cc files to *.cpp, or tell CMake some other way that they're all C++.

        Or if you really do need to mix C and C++ code, you will need to ensure that the C and C++ headers are also separated - eg consider using a *.hpp extension for the C++ headers.

        Hope that helps point you in the right direction.

        Cheers.

        stackprogramerS Offline
        stackprogramerS Offline
        stackprogramer
        wrote on last edited by
        #3

        @Paul-Colby
        But new question how can mix c and cpp code that we have not any problems.....when i change header file in cpp to hpp we have problems and errors yet.....

        M 1 Reply Last reply
        0
        • stackprogramerS stackprogramer

          @Paul-Colby
          But new question how can mix c and cpp code that we have not any problems.....when i change header file in cpp to hpp we have problems and errors yet.....

          M Offline
          M Offline
          mpergand
          wrote on last edited by
          #4

          @stackprogramer
          Maybe you need to use extern "C"
          https://stackoverflow.com/questions/12066279/using-c-libraries-for-c-programs

          stackprogramerS 1 Reply Last reply
          2
          • M mpergand

            @stackprogramer
            Maybe you need to use extern "C"
            https://stackoverflow.com/questions/12066279/using-c-libraries-for-c-programs

            stackprogramerS Offline
            stackprogramerS Offline
            stackprogramer
            wrote on last edited by
            #5

            @mpergand @Paul-Colby Thanks very much,Finally my problem is solved. I defined a pure cpp layer call c function in it and ...i used this layer in other qt classes...

            1 Reply Last reply
            1
            • stackprogramerS stackprogramer 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