Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!

Forums

OverviewFelgo 2 Support (Qt 5) › qualified import

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

    Theo

    I do a qualified import for felgo (import Felgo 3.0 as FelgoModule) as a solution to namespace problems I had.

    Now I call a method of FileUtils as: fileName = FelgoModule.FileUtils.storageLocation(FelgoModule.FileUtils.DocumentsLocation, nameString)

    this results in a runtime error: TypeError: Property ‘storageLocation’ of object [object Object] is not a function

    How to call this function with a qualified import.??

    #22574

    Alex
    Felgo Team

    Hi,

    you can see examples in the documentation at e.g: https://felgo.com/doc/apps-howto-access-and-store-files/

    The FileUtils are available with the context property fileUtils (lowercase!) just like nativeUtils. For accessing the enums, you can still use the FileUtils type with uppercase.

    Best,
    Alex

    #22576

    Theo

    Hi Alex,

     

    I have read the documentation but the examples do not import Felgo 3.0 in a separate namespace but do the Felgo import as last to prevent namespace errors, something advised by you in several posts. I prefer to import the module in a new namespace as I wrote in the post. Like I said I than get the error storageLocation is not seen as a function of FileUtils, irrespective of using a capital F or not.

    So the question is how to call that function in the qualified namespace?

    #22577

    Alex
    Felgo Team

    I prepared an example following my explanation above:

    import Felgo 3.0 as FelgoModule
    import QtQuick 2.0
          
    FelgoModule.App {
      FelgoModule.NavigationStack {
        FelgoModule.Page {
          title: "Qualified Import"
          
          FelgoModule.AppText {
            text: fileUtils.storageLocation(FelgoModule.FileUtils.DownloadLocation, "_packages/myPackage/myImage.png")
          }
        }
      }
    }
    

    fileUtils is an instance of type FileUtils, available as context property from anywhere. You can read more on the concept of context properties and how to use them yourself here: https://felgo.com/cross-platform-development/how-to-expose-a-qt-cpp-class-with-signals-and-slots-to-qml

    Cheers,
    Alex

    #22578

    Theo

    Ok, thanks Alex.

    I understand that the function call does not need the namespace but the enum does

    Made the change and it works.

    This item is solved

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

RSS feed for this thread

You must be logged in to reply to this topic.