{"id":1319,"date":"2021-07-21T10:49:50","date_gmt":"2021-07-21T08:49:50","guid":{"rendered":"http:\/\/www.thelins.se\/johan\/blog\/?p=1319"},"modified":"2021-07-21T10:49:50","modified_gmt":"2021-07-21T08:49:50","slug":"xmllistmodels-in-qt-6","status":"publish","type":"post","link":"https:\/\/www.thelins.se\/johan\/blog\/2021\/07\/xmllistmodels-in-qt-6\/","title":{"rendered":"XmlListModels in Qt 6"},"content":{"rendered":"\n<p>I had a look at a small <kbd>XmlListModel<\/kbd> based project of mine and started migrating the code from Qt 5.12 to Qt 6.2. The code ports pretty cleanly, but there are some caveats to be aware of.<\/p>\n\n\n\n<p>As I&#8217;m lazy, I started by changing the imports from <kbd>2.12<\/kbd> to <kbd>6.2<\/kbd> and tried running the code. The first changes I had to make was to change the import from <kbd>QtQuick.XmlListModel<\/kbd> to <kbd>QtQml.XmlListModel<\/kbd>. I also learned that the import statement no longer requires a specific version to be specified &#8211; I&#8217;m not sure if I&#8217;m a fan of that quite yet.<\/p>\n\n\n\n<p>The second change was that <kbd>XmlRole <\/kbd>has been renamed to <kbd>XmlListModelRole<\/kbd>, and that it no longer has a <kbd>query <\/kbd>property, but an <kbd>elementName <\/kbd>and <kbd>attributeName <\/kbd>property. I guess that saves Qt from having to implement support for XPath queries, and in my use-case (and most others), this should still be enough.<\/p>\n\n\n\n<p>The last change I had to made was to silence a warning. It is no longer encouraged to connect objects directly to signals in QML. In my case, it was animations triggered by the <kbd>onAdd <\/kbd>and <kbd>onRemove <\/kbd>signals in a model. The trick is to declare the animation (in my case, a pair of <kbd>SequentialAnimation <\/kbd>instances, separately. Provide an <kbd>id <\/kbd>for them, and then call start on that id in the signal handler.<\/p>\n\n\n\n<p>All in all, a quite pleasant migration experience with only superficial API changes to handle. All logic could be used as is. Nice!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had a look at a small XmlListModel based project of mine and started migrating the code from Qt 5.12 to Qt 6.2. The code ports pretty cleanly, but there are some caveats to be aware of. As I&#8217;m lazy, I started by changing the imports from 2.12 to 6.2 and tried running the code. &hellip; <a href=\"https:\/\/www.thelins.se\/johan\/blog\/2021\/07\/xmllistmodels-in-qt-6\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">XmlListModels in Qt 6<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,11,4],"tags":[],"class_list":["post-1319","post","type-post","status-publish","format-standard","hentry","category-embedded","category-kde","category-qt"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/posts\/1319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/comments?post=1319"}],"version-history":[{"count":1,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/posts\/1319\/revisions"}],"predecessor-version":[{"id":1320,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/posts\/1319\/revisions\/1320"}],"wp:attachment":[{"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/media?parent=1319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/categories?post=1319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thelins.se\/johan\/blog\/wp-json\/wp\/v2\/tags?post=1319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}