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. [Solved]TypeError: Cannot read property 'source' of undefined----Should I omit this error message?
Forum Updated to NodeBB v4.3 + New Features

[Solved]TypeError: Cannot read property 'source' of undefined----Should I omit this error message?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 5.5k 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
    stereomatching
    wrote on 29 Jun 2013, 19:35 last edited by
    #1

    Using loader to load the component but always get error(warning?or just a state report?) message

    main.qml
    @
    import QtQuick 2.1
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0
    import QtQuick.Dialogs 1.0

    Rectangle {
    width: 100
    height: 62

    ImageView{
        id:imView
    
        anchors.fill: parent
    }
    
    Image{
        anchors.fill: parent
       //this is where the problem come from
        source: imView.getCurrentFile()
    }
    

    }

    @

    ImageView
    @
    import QtQuick 2.0
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0

    Rectangle {
    width: 100
    height: 62

    function appendFiles(files){
        for(var i = 0; i != files.length; ++i){
            filesModel.append({"source": files[i]})
        }
    }
    

    //this is where the problem come from
    function getCurrentFile(){
    if(loader.status == Loader.Ready){
    return filesModel.get(loader.item.currentRow).source
    }

        return "-1"
    }
    
    ListModel{
        id: filesModel
    }
    
    Loader{
        id: loader
    
        sourceComponent: tableViewHeavyComponent
    }
    
    Component{
        id: tableViewHeavyComponent
    
        TableView{
    
        }
    }
    

    }
    @

    Could I safely omit this error message, if not
    how should I deal with it?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gennon
      wrote on 1 Jul 2013, 06:51 last edited by
      #2

      Are you having a list of images (filenames) and then an image showing the selected image?

      I would perhaps add a signal to the ImageView for when the selected image is ready and then add it to the source of the Image.

      @ ImageView{
      id:imView

          anchors.fill: parent
      
          onReady: imageContainer.source = theImageSource;
      }
      

      Image{
      id: imageContainer
      anchors.fill: parent
      }

      @

      theImageSource would then be a property in the ImageView that exposes the current source for instance. Or you could just use the function.

      This might fix your issue.

      /Gen

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stereomatching
        wrote on 1 Jul 2013, 13:26 last edited by
        #3

        Thanks, I found another solution

        @
        if(layoutLoader.status == Loader.Ready && filesModel.count != 0){
        return filesModel.get(layoutLoader.item.currentRow).source
        //return filesModel.get(tableView.currentRow).source
        }
        @

        Check the number of the ListModel before query the source
        The filesModel can't find property source because I haven't insert
        anything into it

        edit : add one more condition "layoutLoader.item.currentRow != -1", else it would emit error message
        when you do not select any image

        1 Reply Last reply
        0

        1/3

        29 Jun 2013, 19:35

        • Login

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