Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 4 Support (Qt 6) › singleton QML file in Felgo 4

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #24895

    Miran Višner

    Hi,

    I am trying to create costum singleton QML file, for some configuration of my app in Felgo 4.0 and no mattter what I try to do I get value of my costum property: “undefined” but I set that property value to 15 in my singleton QML file.

     

    in my singleton QML file I typed “pragma Singleton” before anything else and I typed:

    set_source_files_properties(MySingleton.qml PROPERTIES
    QT_QML_SINGLETON_TYPE ON
    )

    into my CMakeLists.txt after command that lists all qml/js files. How to make it work?

    #24897

    Alex
    Felgo Team

    Hi Miran,

    could create a small example an post your full code here, to make it easier to see what may be wrong there. You can use the “Code” button in the formatting options to post formatted code here in the forum.

    Best,
    Alex

    #24898

    Miran Višner

     

    //MySingelton.qml
    //in this singleton class I wish to have costum global properties for user interface as (global radious for components, colors for interface (light, dark theme), ...; like Felgo's Theme element, but for my costum controls)
    pragma Singleton
    import QtQuick
    import Felgo
     
    Item {
    
        id: item
        property int testSize: 15
        property bool darkTheme: false
    
    }

    in CmakeList.txt:

    cmake_minimum_required(VERSION 3.24)
    
    project(FarmReportSlo VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(Felgo REQUIRED)
    find_package(Qt6 6.4 COMPONENTS Quick REQUIRED)
    
    # Project identifier and version
    # More information: https://felgo.com/doc/felgo-publishing/#project-configuration
    set(PRODUCT_IDENTIFIER "eu.miranvisner.FarmReportSlo")
    set(PRODUCT_VERSION_NAME "1.0.0")
    set(PRODUCT_VERSION_CODE 1)
    
    # Set either "test" or "publish" stage:
    set(PRODUCT_STAGE "test")
    
    # Optionally set a license key that is used instead of the license key from
    # main.qml file (App::licenseKey for your app or GameWindow::licenseKey for your game)
    # Only used for local builds and Felgo Cloud Builds (https://felgo.com/cloud-builds)
    # Not used if using Felgo Live
    set(PRODUCT_LICENSE_KEY "")
    
    set(FELGO_PLUGINS
    )
    
    # Find all QML/JS files for the QML compiler:
    file(GLOB_RECURSE QmlFiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} qml/*.qml qml/*.js)
    
    set_source_files_properties(qml/MySingleton.qml PROPERTIES
        QT_QML_SINGLETON_TYPE TRUE
    )
    
    # Find all non-QML/JS files in the qml and assets folder to add as resources:
    file(GLOB_RECURSE AssetsFiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} assets/* qml/*)
    list(REMOVE_ITEM AssetsFiles ${QmlFiles})
    
    
    
    qt_add_executable(appFarmReportSlo
        main.cpp
        ${QmlFiles}
        ${AssetsFiles}
    )
    
    
    
    felgo_configure_executable(appFarmReportSlo)
    
    # Deploy resources to build folder/package directly
    # comment for publishing
    deploy_resources("${QmlFiles};${AssetsFiles}")
    
    # Add QML files and resources to QML module to included them via QRC automatically:
    qt_add_qml_module(appFarmReportSlo
        URI FarmReportSlo
        VERSION 1.0
    # uncomment for publishing:
    #    QML_FILES ${QmlFiles}
    #    RESOURCES ${AssetsFiles}
        NO_RESOURCE_TARGET_PATH
    )
    
    
    target_compile_definitions(appFarmReportSlo
        PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
    
    target_link_libraries(appFarmReportSlo PRIVATE Felgo)
    

     

    #24900

    Alex
    Felgo Team

    Hi again,

    the issue is that the qmldir file that is generated, and where the singleton is added automatically with the set_source_files_properties, does not seem to be generated or used correctly at runtime then. We are closer investigating this issue, for now I would suggest the following workaround:

    * Remove the set_source_files_properties entry in CMake, as it does not have the desired effect at the moment
    * Instead create an own qmldir file in the qml folder, and add your singleton there, with e.g.:

    singleton MySingleton 1.0 MySingleton.qml

    I hope this resolves your issue for now. Thanks for reporting your issue and the example.

    Best,
    Alex

    #25179

    drsnowlabs

    Hi all.

     

    Just following up on this, since I got into the same situation. I’m using qt 6.6.1 and this is still an issue. The workaround of adding the “old-style” qmldir file (and adding it under QML_FILES in qt_add_qml_module()) does the trick.

Viewing 5 posts - 1 through 5 (of 5 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded