Results 1 to 2 of 2

Thread: Can not use the modules feature from c++20 with Qt Creator and VS

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Can not use the modules feature from c++20 with Qt Creator and VS

    Hi,
    I am trying to use the modules feature (since C++20) but the compiler does not recognize it. I tried with VS2019 and VS2022 as compilers but the result is the same.

    Below the content of my CMakeLists script:
    Qt Code:
    1. cmake_minimum_required(VERSION 3.5)
    2.  
    3. project(Source LANGUAGES CXX)
    4.  
    5. set(CMAKE_CXX_STANDARD 20)
    6. set(CMAKE_CXX_STANDARD_REQUIRED ON)
    7.  
    8. add_executable(Source main.cpp
    9. AirlineTicket.cppm
    10. AirlineTicket.cpp)
    11.  
    12. target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
    13.  
    14. include(GNUInstallDirs)
    15. install(TARGETS Source
    16. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    17. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    18. )
    To copy to clipboard, switch view to plain text mode 

    And a very simple example of module:
    Qt Code:
    1. export module airline_ticket;
    2.  
    3. import <string>;
    4.  
    5. export class AirlineTicket
    6. {
    7. public:
    8. AirlineTicket();
    9. ~AirlineTicket();
    10.  
    11. double calculatePriceInDollars();
    12.  
    13. std::string getPassengerName();
    14. void setPassengerName(std::string name);
    15.  
    16. int getNumberOfMiles();
    17. void setNumberOfMiles(int miles);
    18.  
    19. bool getHasEliteSuperRewardsStatus();
    20. void setHasEliteSuperRewardsStatus(bool status);
    21.  
    22. private:
    23. std::string m_passengerName;
    24. int m_numberOfMiles;
    25. bool m_hasEliteSuperRewardsStatus;
    26. std::string m_passengerName{ "Unknown Passenger" };
    27. int m_numberOfMiles{ 0 };
    28. bool m_hasEliteSuperRewardsStatus{ false };
    29. };
    To copy to clipboard, switch view to plain text mode 

    When I try to build the project, the compiler does not recognize absolutely anything about the module.
    I import the module in AirlineTicket.cpp with the following code:
    Qt Code:
    1. module airline_ticket;
    2.  
    3. using namespace std;
    4. ...more code...
    To copy to clipboard, switch view to plain text mode 

    Is there anything specific I have to do to write C++20 code?
    Thanx
    Franco Amato

  2. #2
    Join Date
    Oct 2024
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Windows

    Default Re: Can not use the modules feature from c++20 with Qt Creator and VS

    You can try this code

    cmake_minimum_required(VERSION 3.20) # Ensure proper support for C++20 modules

    project(Source LANGUAGES CXX)

    # Set C++20 standard
    set(CMAKE_CXX_STANDARD 20)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)

    # Add executable and module files
    add_executable(Source main.cpp AirlineTicket.cppm AirlineTicket.cpp)

    # Enable C++20 features and experimental module support
    target_compile_features(Source PRIVATE cxx_std_20)
    target_compile_options(Source PRIVATE /experimental:module)

    # Mark AirlineTicket.cppm as a C++ source file
    set_source_files_properties(AirlineTicket.cppm PROPERTIES LANGUAGE CXX)

    # Add installation rules (optional)
    include(GNUInstallDirs)
    install(TARGETS Source
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )

  3. The following user says thank you to OmarDay for this useful post:

    d_stranz (19th December 2024)

Similar Threads

  1. qt-creator on Raspberry Pi 2 (Unknown modules; designer)
    By pirata in forum Installation and Deployment
    Replies: 2
    Last Post: 24th October 2015, 18:14
  2. Replies: 0
    Last Post: 5th September 2015, 01:22
  3. Qt Creator/MingGW on Windows - Problems with XML, OpenGL, etc. modules
    By craigdillabaugh in forum Installation and Deployment
    Replies: 0
    Last Post: 12th January 2011, 18:29
  4. Qt modules on Win
    By Maluko_Da_Tola in forum Newbie
    Replies: 3
    Last Post: 25th July 2010, 13:24
  5. Qt modules
    By ber_44 in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2007, 23:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.