Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with using .qml files in .cpp file

Problem with using .qml files in .cpp file

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chronoske
    wrote on 15 Sept 2011, 08:44 last edited by
    #1

    I have just tried using two .qml files in .cpp file, but it doesn't work.
    Can you help me how to merge the two .qml files so it can work and be used in .cpp file?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on 15 Sept 2011, 09:02 last edited by
      #2

      Can you show your code and detalize your problem?

      --
      Vasiliy

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chronoske
        wrote on 16 Sept 2011, 03:32 last edited by
        #3

        => Vass :

        I have put qml project into qrc...
        and then I use this code...
        @this->view->setSource(QUrl(QString::fromUtf8("qrc:/new/prefix1/scrollbar/scrollbar.qmlproject")));@

        Beside that, I try to use two .qml files in .cpp file :
        => in .cpp file :
        @this->view->setSource(QUrl(QString::fromUtf8("qrc:/new/prefix1/DetailMap.qml")));@
        and then
        this is in DetailMap.qml that use item in ScrollBar.qml

        @...
        ScrollBar {
        id: verticalScrollBar
        width: 12; height: view.height-12
        anchors.right: view.right
        opacity: 0
        orientation: Qt.Vertical
        position: view.visibleArea.yPosition
        pageSize: view.visibleArea.heightRatio
        }

        ScrollBar {
            id: horizontalScrollBar
            width: view.width-12; height: 12
            anchors.bottom: view.bottom
            opacity: 0
            orientation: Qt.Horizontal
            position: view.visibleArea.xPosition
            pageSize: view.visibleArea.widthRatio
        }
        

        }@

        in ScrollBar.qml
        @...
        Item {
        id: scrollBar
        property real position
        property real pageSize
        property variant orientation : Qt.Vertical

        Rectangle {
            id: background
            anchors.fill: parent
            radius: orientation == Qt.Vertical ? (width/2 - 1) : (height/2 - 1)
            color: "white"
            opacity: 0.3
        }
        
        // Size the bar to the required size, depending upon the orientation.
        Rectangle {
            x: orientation == Qt.Vertical ? 1 : (scrollBar.position * (scrollBar.width-2) + 1)
            y: orientation == Qt.Vertical ? (scrollBar.position * (scrollBar.height-2) + 1) : 1
            width: orientation == Qt.Vertical ? (parent.width-2) : (scrollBar.pageSize * (scrollBar.width-2))
            height: orientation == Qt.Vertical ? (scrollBar.pageSize * (scrollBar.height-2)) : (parent.height-2)
            radius: orientation == Qt.Vertical ? (width/2 - 1) : (height/2 - 1)
            color: "black"
            opacity: 0.7
        }
        

        }
        @

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on 16 Sept 2011, 06:18 last edited by
          #4

          I don't think you can pass a .qmlproject file to QDeclarativeView::setSource(), just .qml files. In addition, you cannot pass multiple files to QDeclarativeView::setSource(). As soon as you set a new source the old one is discarded.

          However, the declarative engine automatically loads any referenced QML elements, independent of they are local or in resources files. So if you set DetailMap.qml as your source and you create a ScrollBar element in it, the engine automatically looks for a ScrollBar.qml file at the location DetailMap.qml was loaded from and creates your object.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            chronoske
            wrote on 16 Sept 2011, 07:42 last edited by
            #5

            I have just tried to set DetailMap.qml as my source and then in the rectangle, I put in ScrollBar element like this :
            @
            //...
            ScrollBar {
            id: verticalScrollBar
            width: 12; height: view.height-12
            anchors.right: view.right
            opacity: 0
            orientation: Qt.Vertical
            position: view.visibleArea.yPosition
            pageSize: view.visibleArea.heightRatio
            }

            ScrollBar {
                id: horizontalScrollBar
                width: view.width-12; height: 12
                anchors.bottom: view.bottom
                opacity: 0
                orientation: Qt.Horizontal
                position: view.visibleArea.xPosition
                pageSize: view.visibleArea.widthRatio
            }
            

            }@
            and then I put ScrollBar.qml in the same directory with DetailMap.qml.
            But it doesn't work. Should I put something in the import ?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on 16 Sept 2011, 08:07 last edited by
              #6

              Have you added ScrollBar.qml to your resource file too?
              There has to be an error or warning message that ScrollBar.qml couldn't be resolved. Which path does it contain?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                chronoske
                wrote on 16 Sept 2011, 08:30 last edited by
                #7

                Yeah, I have added ScrollBar.qml to my resource file.
                in the resource file, I added ScrollBar.qml and DetailMap.qml.
                But, when I run the app in the simulator, there is error "qrc:/new/prefix1/DetailMap.qml:2:1: "scrollbar": no such directory"

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  frankiefrank
                  wrote on 3 Oct 2011, 10:58 last edited by
                  #8

                  I have a similar problem, except I'm not using resources. I'm loading a QML source from the file system, but if it references other QML files it fails to load.

                  Any idea?

                  "Roads? Where we're going, we don't need roads."

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    chronoske
                    wrote on 11 Oct 2011, 05:32 last edited by
                    #9

                    you can use applicationviewer from qt qml.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved