Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Dynamic Scene exampe as CMake



  • I am trying to run the DynamicScene example project as a Cmake based project in CLion.
    However I am having problems accessing the conent folder which holds all of the assets.

    The project builds fine, but at runtime the qml file can not resolve the

    import "content" 
    

    statement

    My main.cpp looks like this

        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
    
        const QUrl url(QStringLiteral("qrc:/dynamicscene.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
                    if (!obj && url == objUrl)
                        QCoreApplication::exit(-1);
                }, Qt::QueuedConnection);
        engine.load(url);
    
        return QGuiApplication::exec();
    

    Which is the standard cpp main from the creator.

    My Cmake file looks like this:

    cmake_minimum_required(VERSION 3.5)
    
    project(Scroll)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    #set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(Qt5_DIR "~/Code/Cpp/Qt/5.14.0/gcc_64/lib/cmake/Qt5")
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    
    find_package(Qt5 COMPONENTS Core Quick REQUIRED)
    
    add_executable(Scroll
      Scroll/main.cpp
      Scroll/qml.qrc
    )
    target_compile_definitions(Scroll
      PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
    target_link_libraries(Scroll
      PRIVATE Qt5::Core Qt5::Quick)
    
    
    add_executable(DynamicScene
            DynamicScene/main.cpp
            DynamicScene/qml.qrc
            )
    target_compile_definitions(DynamicScene
            PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
    target_link_libraries(DynamicScene
            PRIVATE Qt5::Core Qt5::Quick)
    

    The scoll project is another example which works fine.

    How can I make the content folder visible to cmake/clion project?


Log in to reply