Results 1 to 20 of 23

Thread: QML Plugin w/ QML resources

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML Plugin w/ QML resources

    findChild returns objects by name based on objectName property, not their id. However using findChild to access some object like that seems really weird to me. I don't know what your elements do so it is hard for me to determine what you are trying to achieve. I just have an impression that you are overcomplicating things How does "NavigationTile" differ from Loader? What is its relation to NavigationPanel?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML Plugin w/ QML resources

    findChild returns objects by name based on objectName property, not their id
    huh? Never heard of that property. I am also not able to find any reference to it in the docs.
    How does "NavigationTile" differ from Loader? What is its relation to NavigationPanel?
    NavigationTile (and NavigationPanel, for that matter) behaves like Loader, in that it loads a QML component and creates an item from it. However, they reside in C++ code because I want to deploy a plugin (and dont want to use Javascript - tried to, didnt seem to work). Essentially, both types are wrappers that instatiate items from QML and parameterize them. NavigationTile describes the tiles nested inside the panel, corresponding to Rectangles inside the GridLayout

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML Plugin w/ QML resources

    Quote Originally Posted by doulos View Post
    huh? Never heard of that property. I am also not able to find any reference to it in the docs.
    QObject::objectName

    NavigationTile (and NavigationPanel, for that matter) behaves like Loader, in that it loads a QML component and creates an item from it. However, they reside in C++ code because I want to deploy a plugin (and dont want to use Javascript - tried to, didnt seem to work). Essentially, both types are wrappers that instatiate items from QML and parameterize them. NavigationTile describes the tiles nested inside the panel, corresponding to Rectangles inside the GridLayout
    It seems an overkill to me to do it from within C++. If you have to have a C++ plugin then why not implement the code in QML, embed it into the C++ plugin using the resource system and then expose the types from within the plugin?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML Plugin w/ QML resources

    It seems an overkill to me to do it from within C++.
    it sure isn't totally convenient, but still better IMO than Javascript. And additionally, I get better deployability (one shared lib vs. multiple QML files)

    If you have to have a C++ plugin then why not implement the code in QML, embed it into the C++ plugin using the resource system and then expose the types from within the plugin?
    but that is exactly what I am trying to to! Now just tell me how, and I am done . Maybe you have an example I can look at?

    regards,
    Chris

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML Plugin w/ QML resources

    Quote Originally Posted by doulos View Post
    it sure isn't totally convenient, but still better IMO than Javascript.
    If you extrapolate that then you will end up saying there is no sense in using QML at all.

    And additionally, I get better deployability (one shared lib vs. multiple QML files)
    As I said, those QML files can be embedded in the plugin library.

    but that is exactly what I am trying to to! Now just tell me how, and I am done . Maybe you have an example I can look at?
    I'd need to look for an example, but the general idea is to expose qml types with paths pointing to the resource system using a qmldir file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML Plugin w/ QML resources

    If you extrapolate that then you will end up saying there is no sense in using QML at all.
    I dont agree. Right now I have the overall design nicely kept in QML, and I like it. Setting that up in C++ would be a nightmare. However, I am keeping the dymamic code in C++
    the general idea is to expose qml types with paths pointing to the resource system using a qmldir file.
    sorry to say, but that is way too general to be useful. I have already spent a couple of days working/investigation on this. I am also not sure that you have caught on to my problem: I am loading the QML file as a resource embedd within the shared lib, no qmldir involved. What I am looking for is an example of a C++ plugin which loads an embedded QML component and somehow exposes that as a custom type.

    thanks

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML Plugin w/ QML resources

    The easiest way to do it is to have a regular directory structure containing qml files, put that all into qrc file and use QQmlEngine::addImportPath() where you will point to the qrc file. In my opinion having a C++ component whose only task is to expose a QML type that is already in a QML file makes no sense. If you already have a QML file and you want to expose it to QML then do that directly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML Plugin w/ QML resources

    Just saying: if you are using findChild() to get access to an object defined in a QML scene, you are almost certainly doing something less than ideal.

    It creates a dependency of the C++ code toward the QML code, something one usually wants to avoid (goal being that the UI depends on the compiled code, not the other way around).

    Cheers,
    _

  9. #9
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML Plugin w/ QML resources

    In my opinion having a C++ component whose only task is to expose a QML type that is already in a QML file makes no sense
    agreed. My plugin does a lot more, this is just the reduction of one problem.

    I'll try again. Heres the QML interface I want to offer to my client:

    Qt Code:
    1. NavigationPanel {
    2. rows: 2
    3. columns: 2
    4. cellSpacing: 5
    5. cellPadding: 2
    6.  
    7. NavigationTile {
    8. color: "read"
    9. image: "some.png"
    10. columnSpan: 1
    11. rowSpan: 2
    12. target: "someother.qml"
    13. }
    14.  
    15. NavigationTile {
    16. color: "read"
    17. image: "some.png"
    18. target: "someother.qml"
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    now, internally, the QML representation for NavigationPanel and NavigationTile will be much more complex. NavigationPanel will consist of 2 nested Rectangles (the outer one being the one the navigation target item is placed into when a tile is clicked), and a nested GridLayout. The NavigationTile contains, among other things, a Loader object that will load the target page. The internal representations should not be exposed to the clients of my component, they should only need to write the code shown above.

    As I see it, implementing this will always involve a lot of imperative code, which I prefer to write in C++ (I actually tried Javascript, but got stuck)

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML Plugin w/ QML resources

    I don't see a need for any complex imperative code here. I don't know what you have so far so let's try from scratch... BTW. I didn't test the code below, so it can contain minor errors but the general idea should be valid.

    NavigationPanel -- contains two rectangles and a grid layout:

    javascript Code:
    1. import QtQuick 2.2
    2. import QtQuick.Layouts 1.0
    3.  
    4. Item {
    5. id: root
    6.  
    7. property alias rows: grid.rows
    8. property alias columns: grid.columns
    9. property alias cellSpacing: grid.rowSpacing
    10. property int cellPadding: 0
    11.  
    12. default property list<NavigationTile> tiles
    13.  
    14. Rectangle {
    15. id: outer
    16.  
    17. Rectangle {
    18. id: inner
    19. }
    20. }
    21.  
    22. GridLayout {
    23. id: grid
    24. columnSpacing: rowSpacing
    25.  
    26. Repeater {
    27. model: root.tiles
    28.  
    29. Item {
    30. margins: root.cellPadding
    31. Image {
    32. anchors.fill: parent
    33. source: modelData.image
    34. }
    35. Rectangle {
    36. anchors.fill: parent
    37. color: modelData.color
    38. }
    39. Layout { rowSpan: modelData.rowSpan; columnSpan: modelData.columnSpan }
    40.  
    41. }
    42. }
    43. }
    44. }
    To copy to clipboard, switch view to plain text mode 

    NavigationTile -- definition of a tile

    javascript Code:
    1. import QtQuick 2.2
    2.  
    3. QtObject {
    4. id: tile
    5.  
    6. property color color
    7. property string image
    8. property int columnSpan: 1
    9. property int rowSpan: 1
    10. property string target
    11. }
    To copy to clipboard, switch view to plain text mode 

    What's next?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML Plugin w/ QML resources

    looks not bad, actually . At least at first sight I can see how this might fit my bill. It seems that wrapping ones head around this paradigm is not as easy as one would think. There are several things in your code which can understand when I read them, but don't see how I would have come up with them. I am not in my Qt office right now, so I will try it out tomorrow and report. Thanks much so far

    What's next?
    what if I insisted on doing this in C++? Just joking..

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML Plugin w/ QML resources

    Quote Originally Posted by doulos View Post
    looks not bad, actually . At least at first sight I can see how this might fit my bill. It seems that wrapping ones head around this paradigm is not as easy as one would think. There are several things in your code which can understand when I read them, but don't see how I would have come up with them. I am not in my Qt office right now, so I will try it out tomorrow and report. Thanks much so far
    Here is an actually working code:

    javascript Code:
    1. import QtQuick 2.2
    2. import QtQuick.Layouts 1.0
    3.  
    4. Item {
    5. id: root
    6.  
    7. property alias rows: grid.rows
    8. property alias columns: grid.columns
    9. property alias cellSpacing: grid.rowSpacing
    10. property int cellPadding: 0
    11.  
    12. //default property list<NavigationTile> tiles
    13. property list<NavigationTile> tiles
    14.  
    15. default property alias __tiles: root.tiles
    16.  
    17. Rectangle {
    18. id: outer
    19.  
    20. Rectangle {
    21. id: inner
    22. }
    23. }
    24.  
    25. GridLayout {
    26. id: grid
    27. columnSpacing: rowSpacing
    28. anchors.fill: parent
    29.  
    30. Repeater {
    31. model: root.tiles
    32.  
    33. Item {
    34. anchors.margins: root.cellPadding
    35. implicitWidth: 100
    36. implicitHeight: 100
    37. Image {
    38. anchors.fill: parent
    39. source: modelData.image
    40. z: 1
    41. }
    42. Rectangle {
    43. anchors.fill: parent
    44. color: modelData.color
    45. }
    46. Layout.rowSpan: modelData.rowSpan
    47. Layout.columnSpan: modelData.columnSpan
    48.  
    49.  
    50. }
    51. }
    52. }
    53.  
    54. }
    To copy to clipboard, switch view to plain text mode 

    javascript Code:
    1. import QtQuick 2.2
    2.  
    3. QtObject {
    4. id: tile
    5.  
    6. property color color
    7. property string image
    8. property int columnSpan: 1
    9. property int rowSpan: 1
    10. property string target
    11. }
    To copy to clipboard, switch view to plain text mode 

    And main qml file:

    javascript Code:
    1. import QtQuick 2.2
    2.  
    3. NavigationPanel {
    4. width: 600
    5. height: 400
    6. columns: 2
    7. rows: 2
    8.  
    9. NavigationTile {
    10. color: "red"
    11. image: "/usr/share/icons/default.kde4/64x64/apps/kde.png"
    12. rowSpan: 2
    13. }
    14. NavigationTile {
    15. color: "yellow"
    16. image: "/usr/share/icons/default.kde4/64x64/apps/kontact.png"
    17. }
    18. NavigationTile {
    19. color: "orange"
    20. image: "/usr/share/icons/default.kde4/64x64/apps/ktip.png"
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 


    what if I insisted on doing this in C++? Just joking..
    Then I would continue to say it was an overkill and a waste of effort. I don't know which part you'd want to do in C++.

    At this pace we'll have implemented a complete Metro UI by the end of next week...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Jul 2014
    Location
    Gelnhausen, Germany
    Posts
    21
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML Plugin w/ QML resources

    one more related question: now that I have these pretty QML files that are usable from all my Metro-UI-like applications, how do I deploy them? I don't like the idea of having to copy them over to each deployment machine, and set the QML_IMPORT_PATH environment variable so they are found. I also dont like the idea of having to copy them to each application project and add them to the local resources.

    Also, I wonder how I would maintain these files from within QtCreator. AFAIK there is not project type "QML library" that would only contain QML files and a qmldir file. My ideal solution would be to be able to setup such a project, then define a dependency from the application project to this one, and have the build system automatically package the QML files from the "library" within the application resources. But as it stands, this looks like all manual work.. or did I again overlook something?

    Suggestions?

Similar Threads

  1. Is it possible to add QT resources to a DLL?
    By cboles in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2017, 00:12
  2. Replies: 19
    Last Post: 12th June 2014, 07:30
  3. Plugin embedded resources fails to load
    By deadbird in forum Qt Programming
    Replies: 1
    Last Post: 10th June 2011, 21:09
  4. Replies: 1
    Last Post: 8th October 2010, 11:38
  5. Qt Resources
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 3rd October 2008, 16:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.