Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to give source attribute in image while using repeater in qml??
Forum Updated to NodeBB v4.3 + New Features

how to give source attribute in image while using repeater in qml??

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 2 Posters 1.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.
  • BharathiB Offline
    BharathiB Offline
    Bharathi
    wrote on last edited by p3c0
    #1

    How to give source file path for image when using repeater in qml??

    Repeater
    {
        model:4
        Rectangle
        {
            x:xarray[index];
            y:yarray[index];
            width:widtharray[index];
            height:heightarray[index];
            Image{
               source:img1_array[0]; 
            }
        }
    }
    
    1 Reply Last reply
    0
    • BharathiB Offline
      BharathiB Offline
      Bharathi
      wrote on last edited by
      #2

      In the above code all the arrays are declared in cpp,using context property it is used in qml.For source I want to change the total array based on the repeater change ???Any suggestions to solve this??

      1 Reply Last reply
      0
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        @Bharathi

        For source I want to change the total array based on the repeater change ?

        It is not quite clear what you are trying to do ? Do you mean you want to modify the whole C++ array even if there is 1 change in the array ?
        May be you should check for onModelChanged handler ?

        157

        1 Reply Last reply
        1
        • BharathiB Offline
          BharathiB Offline
          Bharathi
          wrote on last edited by p3c0
          #4

          @p3c0
          Sorry for the inconvinience I am having 4 different arrays for 4 different models.But I am struggling to use it in repeater

          Repeater{
          Model:4
          Image{
          //for 1st model I want the source as 
            source:img1_array[0];
          //for 2nd model I want the source as
             source:img2_array[0];
          //for 3rd model I want the source as
             source:img3_array[0];
          
          }
          }
          
          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            @Bharathi What is img1_array[0] and so on ?
            What does it return ?
            How is it exposed from C++ to QML ?

            157

            1 Reply Last reply
            1
            • BharathiB Offline
              BharathiB Offline
              Bharathi
              wrote on last edited by
              #6

              @p3c0 img_array[0] It just return local file path as string from c++ to display the image.img_array is declared as string list in c++.

              p3c0P 1 Reply Last reply
              0
              • BharathiB Bharathi

                @p3c0 img_array[0] It just return local file path as string from c++ to display the image.img_array is declared as string list in c++.

                p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

                @Bharathi You can't access string list directly from QML unless make it accessible from C++.
                Have a look at following:
                http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html
                http://doc.qt.io/qt-5/qtqml-cppintegration-contextproperties.html

                Perhaps you should add a Q_INVOKABLE function in the model which will return the path from your string list depending upon the index.

                157

                1 Reply Last reply
                1

                • Login

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