[Solved] [Qt5] How register my own QIODevice (replacement of QAbstractFileEngineHandler)



  • We have to use our own file-system on every platforms (android, iOS, Windows,...) to make our application accessing to resources.
    We already have an API that allow our own code to access those files, but the Qt part (QML Engine) don't know it. Is there a way to register a wrapper of that API that the QML Engine will be able to use?

    It seems existing on the branch 4 of Qt, but not in the 5.

    If there is no replacement of old API of Qt (QFSFileEngine, QAbstractFileEngineHandler,...), how I can access it? And is there a link with QIODevice?


  • Lifetime Qt Champion

    Hi,

    It's still there but became private (with the implication that it might disappear anytime without warning) so you'll have to add something like

    @QT += core-private@

    to your pro file in order to use it.



  • Thank you, because for the moment I have some include path with the version number of Qt.

    It seems working fine else, I just have some difficulties to make the QML engine loading correctly my files. I don't know exactly why but it fails load a component. Three previous loaded files by the QML engine are the root QML containing a loader to the main.qml that import a js can correctly loaded too.


  • Lifetime Qt Champion

    You should note have such includes. Either use

    @#include <QtCore/QObject>@

    or just

    @#include <QObject>@

    But no version number



  • Thank you a lot, it's much better now.

    May have you an idea on what can cause the qml engine not finding components?

    Here is my logs :
    @
    D/Qt ( 5463): ....\Source\GUI_QML\ResourcesDevice.cpp:279 (virtual void qml::ResourcesEngine::setFileName(const QString&)): ResourcesEngine::setFileName : "main.1.fr.anuman.HomeDesign3D.obb/qml/Main.qml"
    D/Qt ( 5463): ....\Source\GUI_QML\ResourcesDevice.cpp:279 (virtual void qml::ResourcesEngine::setFileName(const QString&)): ResourcesEngine::setFileName : "main.1.fr.anuman.HomeDesign3D.obb/qml/Utils.js"
    D/Qt ( 5463): ....\Source\GUI_QML\ResourcesDevice.cpp:279 (virtual void qml::ResourcesEngine::setFileName(const QString&)): ResourcesEngine::setFileName : "main.1.fr.anuman.HomeDesign3D.obb/qml"
    W/Qt ( 5463): file:///data/data/fr.anuman.HomeDesign3D/files/main.1.fr.anuman.HomeDesign3D.obb/qml/Main.qml:17 ((null)): file:///data/data/fr.anuman.HomeDesign3D/files/main.1.fr.anuman.HomeDesign3D.obb/qml/Main.qml:17:5: ProjectInfo is not a type
    @

    ProjectInfo component is in the "main.1.fr.anuman.HomeDesign3D.obb/qml" folder for which I return fileFlags : All read permissions, exists, directory and all execution permissions.
    I got the error just after the last call of my QAbstractFileEngine::fileFlags(FileFlags type) implementation.



  • We also using cmake, do you know how I import a private module with it?

    I tried that :
    find_package(Qt5Core ${QT_MIN_VERSION} REQUIRED Private)

    without success.

    My header #include <QtCore/private/qabstractfileengine_p.h> can't be found.


  • Lifetime Qt Champion

    Without any code, initialization etc… I can't tell



  • I finally made it work on Windows, but not Android that is my main target for the moment.
    The issue was my read implementation that didn't return the correct size cause I mess the check of the end of file.
    I am using the same code and package file on android but I still have the same issue.

    What part of code do you need?

    Is there a way to associate Qt code to the debugger to be able to understand where it failed to load the component and for what condition? That was the method I used to find the issue on read implementation.


  • Lifetime Qt Champion

    You can use the debugger the same way

    The implementation of your custom file engine handler, however it might be easier if the code is big to either use a pastbin site or if you have a repository to look at



  • I had try to add mapping to Qt sources to the debugger, but I am not able to see it, QtCreator always show me the asm of Qt.

    I have found a little workaround, I can load qml files from the user backup directory and images from my package, so the issue seems to be specific of the way qml files are loaded. I certainly do something wrong with text file that cause some parsing issues, but it strange in this case that it's works on Windows.

    Here is my implementation of the QAbstractFileEngine :
    http://pastebin.com/ZnMFVdDV
    http://pastebin.com/rf9wuein


  • Lifetime Qt Champion

    @mCurrentDir = QDir::current().path() + "/";@

    Looks dangerous to me, it's probably not what you assume it is on android



  • I have a question about the QFileInfo QAbstractFileEngineIterator::currentFileInfo() const method.
    How the implementation made in my derived class can generate a QFileInfo with right properties? Like if the entry is a file or a directory?



  • [quote author="SGaist" date="1410898531"]@mCurrentDir = QDir::current().path() + "/";@

    Looks dangerous to me, it's probably not what you assume it is on android[/quote]

    You are right, it's certainly better for my to check if the path contains my package name then removing everything before to clean file path.


  • Lifetime Qt Champion

    If you want you own application folder your can use Q(Gui)Application for that.



  • [quote author="SGaist" date="1410986525"]If you want you own application folder your can use Q(Gui)Application for that.[/quote]

    Yes we already use it for some other things.

    Thank you a lot for all of your help.

    How I can mark this thread a resolved?


  • Lifetime Qt Champion

    You're welcome !

    Just edit your original post and update the thread title :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.