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. How to assign image source during runtime in QML

How to assign image source during runtime in QML

Scheduled Pinned Locked Moved General and Desktop
19 Posts 2 Posters 9.8k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    subram_QT
    wrote on last edited by
    #7

    Hi
    In 5.1.0 QT version , if a QML project is created the following error is displayed

    In my header file i included

    "#include <QQmlContext>"

    "Main.h:3: error: C1083: Cannot open include file: 'QQmlContext': No such file or directory"

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #8

      Make sure you have added Qml module to your project file:
      @
      QT += qml

      or, to have everything in:

      QT += core gui qml quick
      @

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        subram_QT
        wrote on last edited by
        #9

        after adding "QT+=qml" in additional arguments of build steps , i am getting following error.

        wrcMain.h:4: error: C1083: Cannot open include file: 'QQuickView': No such file or directory.

        Actually i crated a QML project , still why these errors are coming, The same project i crated for 5.02 there was no error ?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #10

          How should I know? Clearly something is wrong, but I can't say what or where without more info.

          Don't modify the build steps. Open your project file (usualy <yourProjectName>.pro) and add it there.

          For this second error, obviously you need to add:
          @
          QT += quick
          @

          (Z(:^

          1 Reply Last reply
          0
          • S Offline
            S Offline
            subram_QT
            wrote on last edited by
            #11

            Thanks , i had added in .pro file

            1 Reply Last reply
            0
            • S Offline
              S Offline
              subram_QT
              wrote on last edited by
              #12

              Hi

              Now i would like to do transition between QML files . by having one part of screen as static .

              1.How can i do the view/screen transiiton in QML
              2.how will i create a static view that can be shown in all view.

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #13

                See "this":http://www.youtube.com/watch?v=cOViDcYWNCI.

                (Z(:^

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  subram_QT
                  wrote on last edited by
                  #14

                  Hi

                  How to perform animation for image(.png files)
                  I would like to make the image visibility to false after some duration

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #15

                    Please, read the documentation, it is really well-written...

                    Here:
                    @
                    Image {
                    id: myImg
                    source: "somesource.png"
                    opacity: 1.0
                    NumberAnimation on opacity { duration: 2000 }
                    }
                    @

                    Then simply change opacity to 0.0 somewhere in your code.

                    (Z(:^

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      subram_QT
                      wrote on last edited by
                      #16

                      Hi

                      I actually tried to set the visible property after the number animation , but its not working.

                      @Image {

                          property int currentImage ;
                          id: startup
                          x: 46
                          y: 64
                          width: 223
                          height: 175
                          z: 5
                          rotation: 0
                          scale: 0.7
                          fillMode: Image.PreserveAspectCrop
                          clip: true
                          source: "images/start.png"
                          visible: true
                          opacity : 1.0
                          NumberAnimation on opacity { to: 0.0; duration: 4000 }
                          NumberAnimation on scale { to: 1.3; duration: 4000 }
                          Component.onCompleted:{ start_menu.visible = true}
                      
                      
                      
                      }
                      

                      Image {
                      id: start_menu
                      source: "images/Setting.png"
                      anchors.bottom: stop.bottom
                      anchors.bottomMargin: -210
                      anchors.left : stop.down
                      anchors.leftMargin: 10
                      visible: false
                      }@

                      I tried to display startup image to be displayed first and get invisible and then start_menu to be diaplayed

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        subram_QT
                        wrote on last edited by
                        #17

                        But both the images are getting displayed together and startup get invisible due to number animation

                        1 Reply Last reply
                        0
                        • sierdzioS Offline
                          sierdzioS Offline
                          sierdzio
                          Moderators
                          wrote on last edited by
                          #18

                          QML is declarative. It means that when you add a NumberAnimation it will only work then the property is changed. It is not imperative code like in C++ that tells the engine to run the animation. If you want it to run, you need to trigger it by running start(), or changing the value in question.

                          I don't have time now to explain fully, here is a piece of code that will work a bit, but it is not a full solution to your problem. Better use states to achieve it.
                          @
                          visible: true
                          opacity : 1.0
                          NumberAnimation on opacity { duration: 4000 }
                          NumberAnimation on scale { duration: 4000
                          onRunningChanged: {
                          if (!running)
                          start_menu.visible = true;
                          }
                          }
                          Component.onCompleted:{
                          opacity = 0.0; // this should start the animation
                          scale = 1.3;
                          }
                          @

                          (Z(:^

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            subram_QT
                            wrote on last edited by
                            #19

                            Hi
                            Thanks for your reply

                            I ma getting error as below

                            Cannot assign to non-existent property "onRunningChanged"
                            onRunningChanged: {

                            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