Results 1 to 10 of 10

Thread: QML's import does not work

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question QML's import does not work

    Dear Sirs and Madams!

    I have following code chunk:
    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.Window 2.1
    3. import QtQuick.Controls 1.2
    4. import QtQuick.Controls.Styles 1.2
    5. import QtQuick.Layouts 1.1
    6.  
    7. import "components"
    8.  
    9. ApplicationWindow
    10. {
    11. id: fsaWindowMain
    12.  
    13. property int fsaWindowWidth: 800
    14. property int fsaWindowHeight: 400
    15. property int fsaSpacingHoriz: 8
    16. property int fsaSpacingVert: 8
    17. property int fsaToolBarHeight: 48
    18.  
    19. visible: true
    20.  
    21. width: fsaWindowWidth
    22. height: fsaWindowHeight
    23.  
    24. color: "black"
    25.  
    26. toolBar: fsaToolbarMain
    27. statusBar: fsaStatusBarMain
    28.  
    29. ToolBar
    30. {
    31. id: fsaToolbarMain
    32.  
    33. width: parent.width
    34. height: fsaToolBarHeight
    35.  
    36. fsaMenuItem
    37. {
    38. fsaMenuItemWidth: width
    39. fsaMenuItemHeight: height
    40. fsaMenuItemRadius: 32
    41. fsaMenuItemText: "text1"
    42. }
    43. }
    44.  
    45. StatusBar
    46. {
    47. id: fsaStatusBarMain
    48.  
    49. width: parent.width
    50. height: fsaToolbarMain.height
    51. }
    52. }
    To copy to clipboard, switch view to plain text mode 
    Now, fsaMenuItem is declared in fsaMenuItem.qml in components subdir:
    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle
    4. {
    5. id: fsaMenuItem
    6.  
    7. property int fsaMenuItemWidth: 128
    8. property int fsaMenuItemHeight: parent.height
    9. property int fsaMenuItemRadius: 32
    10. property string fsaMenuItemText: ""
    11.  
    12. width: fsaMenuItemWidth
    13. height: fsaMenuItemHeight
    14.  
    15. radius: fsaMenuItemRadius
    16.  
    17. Text
    18. {
    19. color: "white"
    20. text: qsTr(fsaMenuItemText)
    21. }
    22.  
    23. color: "black"
    24. }
    To copy to clipboard, switch view to plain text mode 
    And the directory hierhcary is as follows:dirHierchary.PNGWhy does import clause does not import fsaMenuItem?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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's import does not work

    All QML component names need to begin with a capital letter.
    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.


  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML's import does not work

    Quote Originally Posted by wysota View Post
    All QML component names need to begin with a capital letter.
    If I put a capital in component name, I get
    Unknown Id (M14)
    error. Here is screenshot:m14InvalidId.png
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML's import does not work

    But you have changed the id, not the component name. Component name is the name of the file where this component is defined. And you use that name to instantiate the object of that type.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. The following user says thank you to faldzip for this useful post:

    MarkoSan (7th September 2014)

  6. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML's import does not work

    Quote Originally Posted by faldzip View Post
    But you have changed the id, not the component name. Component name is the name of the file where this component is defined. And you use that name to instantiate the object of that type.
    So the filename (component name), must begin with capital?
    Qt 5.3 Opensource & Creator 3.1.2

  7. #6
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML's import does not work

    Now the code finds component, but at runtime the file cannot be found:
    Starting D:\xxxxx\xxxxx\Software\fsaInteractor\bin\x86\debu g\debug\fsaInteractor.exe...
    QML debugging is enabled. Only use this in a safe environment.
    QQmlApplicationEngine failed to load component
    qrc:/FsaQmlMain:36 Type FsaComponents.FsaMenuItem unavailable
    qrc:/components/FsaMenuItem.qml:-1 File not found
    Here is qml.qrc file listing:
    Qt Code:
    1. <RCC>
    2. <qresource lang="English" prefix="/">
    3. <file alias="FsaQmlMain">main.qml</file>
    4. </qresource>
    5. <qresource lang="English" prefix="/components">
    6. <file alias="FsaQmlMenuItem">components/FsaMenuItem.qml</file>
    7. </qresource>
    8. </RCC>
    To copy to clipboard, switch view to plain text mode 
    and here is directory listing:
    dirStructure.jpg

    Why the file is not being found?

    Sincerely,
    Marko
    Qt 5.3 Opensource & Creator 3.1.2

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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's import does not work

    Because you have aliased its name.
    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.


  9. The following user says thank you to wysota for this useful post:

    MarkoSan (8th September 2014)

  10. #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's import does not work

    Try to specify the URL for your main QML file as "qrc:///main.qml" instead of "qrc:/main.qml"

    Cheers,
    _

  11. #9
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QML's import does not work

    Quote Originally Posted by anda_skoa View Post
    Try to specify the URL for your main QML file as "qrc:///main.qml" instead of "qrc:/main.qml"

    Cheers,
    _
    But it is not the problem in main.qml (main.qml works fine), it is problem in the one of imported elements, FsaMenuItem.qml.
    Qt 5.3 Opensource & Creator 3.1.2

  12. #10
    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's import does not work

    Quote Originally Posted by MarkoSan View Post
    But it is not the problem in main.qml (main.qml works fine), it is problem in the one of imported elements, FsaMenuItem.qml.
    Yes, that was obivous.
    Nevertheless can the base URL affect resolution of subsequent URLs

    Cheers,
    _

Similar Threads

  1. Cannot import my graph
    By Stanfillirenfro in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2014, 21:41
  2. Qt 4.5 import stylesheet
    By dcoppenb in forum Qt Programming
    Replies: 0
    Last Post: 7th March 2013, 12:47
  3. How to import qss into another qss file
    By bedbuffer in forum Newbie
    Replies: 1
    Last Post: 4th April 2011, 11:22
  4. import pdf in a QGraphicsView
    By tilsitt in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2011, 16:18
  5. How do i import and use a DLL like Skype4COM.dll in Qt4?
    By fernando in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2010, 07:22

Tags for this Thread

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.