Results 1 to 20 of 25

Thread: Is it possible to dynamically populate a ListView within a GridView ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2016
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Quote Originally Posted by anda_skoa View Post
    We could safe some time if you tell me how often I should repeat the question on whether the property getter is being called before you deem it worthy to be answered, then I can just do that in a single posting.

    Unless of course you don't want to narrow down the problem?

    Cheers,
    _
    I should read more carefully, my bad...

    You're right, the getters of my OverviewEntry are well called but none of the ChannelEntry's one. (by the way, the ChannelEntry object is used elsewhere in the code and qml and worked well in a usual usage)

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Ok, so OverviewEntry::channel() is called for all instances of OverViewEntry?
    And each call returned a non-empty list?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2016
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Quote Originally Posted by anda_skoa View Post
    Ok, so OverviewEntry::channel() is called for all instances of OverViewEntry?
    And each call returned a non-empty list?

    Cheers,
    _
    Exactly, that's why I suspect I misunderstood the way Qt is working behind the scene.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Ok, so lets summarize:

    - Your OverviewEntry QML instances are created
    - They display the value of the name property
    - They call the channels() getter when assigning to the ListView's model property
    - The channels() getters return a correct, non-empty QList<ChannelEntry*>
    - The ListView counts are 0

    What kind of output do you get when you put this into the ListViews
    Qt Code:
    1. onModelChanged: console.log("model for " + modelData.name + " is " + model);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Mar 2016
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Quote Originally Posted by anda_skoa View Post
    Ok, so lets summarize:

    - Your OverviewEntry QML instances are created
    - They display the value of the name property
    - They call the channels() getter when assigning to the ListView's model property
    - The channels() getters return a correct, non-empty QList<ChannelEntry*>
    - The ListView counts are 0

    What kind of output do you get when you put this into the ListViews
    Qt Code:
    1. onModelChanged: console.log("model for " + modelData.name + " is " + model);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _
    I just made the test and this is the output :


    • qml: model for OverviewEntry 1 is QVariant(QList<ChannelEntry*>)
    • qml: model for OverviewEntry 2 is QVariant(QList<ChannelEntry*>)
    • qml: model for OverviewEntry 3 is QVariant(QList<ChannelEntry*>)
    • qml: model for OverviewEntry 4 is QVariant(QList<ChannelEntry*>)
    • qml: model for OverviewEntry 5 is QVariant(QList<ChannelEntry*>)
    • qml: model for OverviewEntry 6 is QVariant(QList<ChannelEntry*>)

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Hmm.
    You also have
    Qt Code:
    1. Q_DECLARE_METATYPE(QList<ChannelEntry*>);
    To copy to clipboard, switch view to plain text mode 
    have you tried adding
    Qt Code:
    1. Q_DECLARE_METATYPE(ChannelEntry*);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  7. #7
    Join Date
    Mar 2016
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Quote Originally Posted by anda_skoa View Post
    Hmm.
    You also have
    Qt Code:
    1. Q_DECLARE_METATYPE(QList<ChannelEntry*>);
    To copy to clipboard, switch view to plain text mode 
    have you tried adding
    Qt Code:
    1. Q_DECLARE_METATYPE(ChannelEntry*);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _
    I tried but it doesn't change anything. Even with these two Q_DECLARE_METATYPE commented, it works same way.

    But if I comment :

    Qt Code:
    1. //Main.cpp
    2. ...
    3. qmlRegisterType<ChannelEntry>("ChannelEntry", 1, 0, "ChannelEntry");
    4. ...
    To copy to clipboard, switch view to plain text mode 

    The app crashed...

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Probably because you are now using the same name for the registered type and the QML element type.
    Change the second string argument here and maybe also use qmlRegisterUncreatableType()

    Cheers,
    _

  9. #9
    Join Date
    Mar 2016
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Quote Originally Posted by anda_skoa View Post
    Probably because you are now using the same name for the registered type and the QML element type.
    Change the second string argument here and maybe also use qmlRegisterUncreatableType()

    Cheers,
    _
    I tried by refactoring my C++ type ChannelEntry into QChannelEntry and setting :

    Qt Code:
    1. //Main.cpp
    2. ...
    3. qmlRegisterType<QChannelEntry>("ChannelEntry", 1, 0, "QChannelEntry");
    4. qmlRegisterUncreatableType<QChannelEntry>("ChannelEntry", 1, 0, "QChannelEntry","");
    5. ...
    To copy to clipboard, switch view to plain text mode 

    And the only change is the result of your debug output :

    • qml: model for OverviewEntry 1 is QVariant(QList<QChannelEntry*>)
    • qml: model for OverviewEntry 2 is QVariant(QList<QChannelEntry*>)
    • qml: model for OverviewEntry 3 is QVariant(QList<QChannelEntry*>)
    • qml: model for OverviewEntry 4 is QVariant(QList<QChannelEntry*>)
    • qml: model for OverviewEntry 5 is QVariant(QList<QChannelEntry*>)
    • qml: model for OverviewEntry 6 is QVariant(QList<QChannelEntry*>)


    Remark : I also tried by commenting qmlRegisterType or qmlRegisterUncreatableType but with no success

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Ok, strange.

    Can you try to create a minimal example that can be built and run and shows the problem?

    Cheers,
    _

  11. #11
    Join Date
    Mar 2016
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Sorry for the late reply but I haven't got the time until now.

    I made this little example which build and run but with the same problem.

    ListViewExample.zip

    I hope it helps to understand the issue.

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to dynamically populate a ListView within a GridView ?

    Ok, this is more complicated than I thought

    I found two things that work:
    - make the channels property a QList<QObject*>
    - Use a QAbstractListModel derived class to provide the channel data

    Some other observations:
    - main.cpp cannot compile because there is no MainWindow.h, it is mainwindow.h
    - this can be written much shorter. Instead of
    Qt Code:
    1. QString::fromStdString("channel " + QString::number(i).toStdString()).toStdString().c_str())
    To copy to clipboard, switch view to plain text mode 
    write this
    Qt Code:
    1. QString("channel %1").arg(i);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  13. The following user says thank you to anda_skoa for this useful post:

    andrioli.n (14th March 2016)

Similar Threads

  1. Replies: 0
    Last Post: 16th October 2015, 16:51
  2. GridView without reflow
    By shaolin in forum Qt Quick
    Replies: 15
    Last Post: 12th May 2014, 14:14
  3. Replies: 7
    Last Post: 9th September 2013, 08:31
  4. Usage of QTableView as gridview
    By ada10 in forum Newbie
    Replies: 7
    Last Post: 9th August 2010, 23:13
  5. Replies: 1
    Last Post: 14th October 2007, 10:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.