Important: Please read the Qt Code of Conduct -

[SOLVED] Pass an Url in a .qrc file from QML to C++

  • Hi,

    I have been hitting the wall again and again and it seems I simply can't do it.

    I want to give a relative path to a file in a qrc file in QML, call a C++ function with this QUrl as a parameter and open the associated file in C++.

    in QML
    @ function run()
    var file = "qrc:///myFile.js"

    In CPP
    @myFunc(const QUrl &fileUrl)
    <open file, read it, etc>

    It seems I can't do such a simple thing...;'(

    Any help would be welcome.

  • Moderators

    Use QString as the function parameter. QFile needs a string anyway, so it will even save you conversion time.

  • It works perfectly! Thanks!

Log in to reply