Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    PathView Using QAbstractListModel Determines Count Late

    QML and Qt Quick
    2
    3
    2287
    Loading More Posts
    • 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.
    • H
      Hornsj2 last edited by

      I'm trying to use a ListModel defined in C++ to supply data to a PathView element.

      I'm using the tutorial below as an example, because I want to create a page control component:

      "Example I'm following":http://wiki.forum.nokia.com/index.php/How_to_create_a_Page_Control_component_in_QML

      @ path: Path {
      startX: - pageControl.width * listModel.count / 2 + pageControl.width / 2
      startY: pageControl.height / 2
      PathLine {
      x: pageControl.width * listModel.count / 2 + pageControl.width / 2
      y: pageControl.height / 2
      }
      }@

      The pathview element is created correctly, with the exception that it is placed incorrectly due to what I believe is a race-condition between initialization of the listModel and the position of the path.

      The problem is with the above section of code. It seems that listModel.count gets updated AFTER the PathView.path is defined, which causes undefined behavior (QML claims a NAN is being used to place the path).

      This happens even though I'm creating the QAbstractListModel, then assigning it to the root context of the view, THEN i'm setting the main QML file.

      I was able to get around the problem by creating a property called pathViewSize and explicitly setting it to the proper count value after adding page elements but this is a hack and I don't like it. Suggestions?

      1 Reply Last reply Reply Quote 0
      • T
        tedmiddleton last edited by

        I'm pretty sure that I'm running into exactly the same problem:

        "http://qt-project.org/forums/viewthread/26441/":http://qt-project.org/forums/viewthread/26441/
        "http://stackoverflow.com/questions/15753419/qt-qml-data-model-doesnt-seem-to-work-with-c":http://stackoverflow.com/questions/15753419/qt-qml-data-model-doesnt-seem-to-work-with-c

        I'm wondering if the Qt bug tracker already lists this? With the source available, I'm tempted to dive into the declarative engine and fix it myself, but without more knowledge of the Qt code base, it would probably take me days to do it.

        1 Reply Last reply Reply Quote 0
        • T
          tedmiddleton last edited by

          Not sure if you're still interested, but I had a conversation with a couple of former Trolltech employees on IRC last night. They helped me with this and I've posted the answer to my StackOverflow question.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post