Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 54

Thread: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

  1. #21
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,484
    Thanks
    252
    Thanked 712 Times in 702 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    When it comes to the copy constructors and assignment operators, I decided to just add them to all the classes because I have been constantly getting errors like: "Can't instanciate abstract class", "class doesn't have appropriate default constructor" "class references deleted constructor". I kept getting these in different variations when I tried to register or use any of the models. So it was more of a temporary duct tape fix rather than a planned class design.
    Beating on your code with a hammer and adding unnecessary code until things finally work doesn't really teach you -what- these errors mean or -why- they occur though. In fact, the code you are adding to get around these errors might actually cause your program to work incorrectly despite compiling and linking. And adding copy constructors and assignment operators to classes that shouldn't have them or failing to copy or assign their base class content (as yours fail to do) means you end up with a class that is only partly copied or assigned. (As an aside, I realize now that is the reason why your QObject-based classes do compile - you aren't calling the forbidden methods of those base classes).

    I have also noticed that I haven't connected the signals. I am working on them now.
    Well, that could explain why your UI doesn't update...
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #22
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Yup, this will definitely be one of the lessons that I will take with me from this project.

    Anyway, some progress. I am now working on why the variables are undefined.

  3. #23
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    As d_stranz said I am puzzled that this even compiles.

    Each usage of a QObject derived class in a copy or assign context should have resulted in a build error, e.g.
    Qt Code:
    1. QList<Album>
    To copy to clipboard, switch view to plain text mode 
    should not build!

    Why did you make the data classes QObject?

    Quote Originally Posted by Nizars View Post
    Qt Code:
    1. this->m_albumsManager = AlbumsManager();
    2. this->m_albumsManagerPointer = &m_albumsManager;
    3.  
    4. this->m_cardsManager = CardsManager();
    5. this->m_cardsManagerPointer = &m_cardsManager;
    6.  
    7. this->m_albumCardsModel = AlbumCardsModel(m_albumsManagerPointer, m_cardsManagerPointer);
    8. this->m_albumCardsModelPointer = &m_albumCardsModel;
    To copy to clipboard, switch view to plain text mode 
    None of this should build.

    Since you need the objects as pointers anyway, just create them on the heap and avoid the unsupported copy.

    Quote Originally Posted by Nizars View Post
    main.cpp:

    Qt Code:
    1. // Core classes
    2. qmlRegisterType<App>("PokeApp.Classes.Core", 1, 0, "App");
    3. qmlRegisterType<Album>("PokeApp.Classes.Core", 1, 0, "Album");
    4. qmlRegisterType<Card>("PokeApp.Classes.Core", 1, 0, "Card");
    5.  
    6. // Manager classes
    7. qmlRegisterType<AlbumsManager>("PokeApp.Classes.Core", 1, 0, "AlbumsManager");
    8. qmlRegisterType<CardsManager>("PokeApp.Classes.Core", 1, 0, "CardsManager");
    To copy to clipboard, switch view to plain text mode 
    Unnecessary, you are not instantiating any of these as QML elements.

    Quote Originally Posted by Nizars View Post
    Qt Code:
    1. // App engine
    2. QQmlApplicationEngine engine;
    3. engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    To copy to clipboard, switch view to plain text mode 
    Missing the setContextProperty() for the objects needed by the QML.


    Quote Originally Posted by Nizars View Post
    Qt Code:
    1. // Context properties
    2. QQmlContext *ctxt1 = engine.rootContext();
    3. ctxt1->setContextProperty("albumCardsModel", mainApp.getAlbumCardsModelPointer());
    4. QQmlContext *ctxt2 = engine.rootContext();
    5. ctxt2->setContextProperty("albumsManager", mainApp.getAlbumsManagerPointer());
    6. QQmlContext *ctxt3 = engine.rootContext();
    7. ctxt3->setContextProperty("cardsManager", mainApp.getCardsManagerPointer());
    To copy to clipboard, switch view to plain text mode 
    Too late, the QML has already failed loading

    Quote Originally Posted by Nizars View Post
    Qt Code:
    1. delegate: Text {
    2. text: "Card\n" +
    3. "Name: " + albumCardsModel.name + ".\n" +
    4. "ID: " + albumCardsModel.cardID + ".\n" +
    5. "Image URL: " + albumCardsModel.imageURL + ".\n" +
    6. "Subtype: " + albumCardsModel.subtype + ".\n" +
    7. "Supertype: " + albumCardsModel.supertype + ".\n" +
    8. "Number: " + albumCardsModel.number + ".\n" +
    9. "Artist: " + albumCardsModel.artist + ".\n" +
    10. "Rarity: " + albumCardsModel.rarity + ".\n" +
    11. "Series: " + albumCardsModel.series + ".\n" +
    12. "Set: " + albumCardsModel.set + ".\n" +
    13. "Set code: " + albumCardsModel.setCode + ".\n" +
    14. "Condition: " + albumCardsModel.condition + ".\n" +
    15. "Status: " + albumCardsModel.status + ".\n"
    16. }
    To copy to clipboard, switch view to plain text mode 
    Each delegate instance shows data from one entry in the model.
    It accesses that specific entry's data through a helper object called "model"
    Qt Code:
    1. text: "Card\n" + "Name: " + model.name
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    Nizars (3rd January 2017)

  5. #24
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Thanks for all the feedback.
    I have created myself a maze of objects flying everywhere.

    I will start to go through all the functions and methods again.
    But for now, I am happy that I am getting closer to the goal I have set for this project.


  6. #25
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Let's say that I have created a couple of Albums and added Cards to them. What options do I have to save what I have done so that the next time I start the app it will continue from where I left off?

    I have comes across QSettings but it seems to mostly involve basic general app settings. I have also come across QSqlDatabases but this seems to involve the implementation of a lot of functions to get it to work with what I have set up. An xml approach seems possible to but a bit easier.

    I was wondering if there is a way to just dump all the data into a file and just load it on start up. I remember doing something like that in c++ and it seemed straightforward if I am not misremembering things. Thinking back about it. I might have created functions that instansiated objects from the information in the file. I better look up that project's files to be sure.


    Added after 9 minutes:


    Edit:
    I added the Q_OBJECT to Album and Card classes because I was trying to figure out how to use them from the QML side. I now understand that it was unnecessary and have reverted those changes. It might have been what was causing all those "no appropriate default constructor" & "class referring to a deleted function" errors that made me create those illegal methods. It's just part of me learning and figuring things out.


    Added after 6 minutes:


    Edit:
    I have also tweaked the Albums page and added a new model for just the Albums.




    Added after 16 minutes:


    Edit

    I have also made some changes that might not make a lot of sense at the moment. main.cpp instantiates an App object, the App objects default constructor creates an instance of each of the manager and model classes. Then in the main.cpp it gets pointers those that need to be set as context properties and the main sets them. the qml register types are also made in the App constructor. I am basically trying to centralize the App class so that i can add to it a save to local file and load from local file methods so that it can act as a manager for the application. the design is a bit messy for now but it goes something like this

    Attached Images Attached Images
    Last edited by Nizars; 4th January 2017 at 01:51.

  7. #26
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Quote Originally Posted by Nizars View Post
    I have comes across QSettings but it seems to mostly involve basic general app settings.
    QSettings is the quickest way, since you only need to save IDs (strings and ints if I see this correctly) and names for the Albums that would be my first go.

    Quote Originally Posted by Nizars View Post
    I have also come across QSqlDatabases but this seems to involve the implementation of a lot of functions to get it to work with what I have set up.
    Not that much more complicated but needs some prior setup and planning (database table layout, etc).

    Quote Originally Posted by Nizars View Post
    An xml approach seems possible to but a bit easier.
    True, but not as easy as QSettings.

    And there is also Qt's JSON classes

    Quote Originally Posted by Nizars View Post
    I was wondering if there is a way to just dump all the data into a file and just load it on start up. I remember doing something like that in c++ and it seemed straightforward if I am not misremembering things.
    Also possible but IMHO even more complicated for little gain.

    Quote Originally Posted by Nizars View Post
    I added the Q_OBJECT to Album and Card classes because I was trying to figure out how to use them from the QML side. I now understand that it was unnecessary and have reverted those changes. It might have been what was causing all those "no appropriate default constructor" & "class referring to a deleted function" errors that made me create those illegal methods. It's just part of me learning and figuring things out.
    Yes, those sounds like errors which could be caused by trying to copy QObject derived classes or using them as element types in containers.

    Quote Originally Posted by Nizars View Post
    I have also made some changes that might not make a lot of sense at the moment. main.cpp instantiates an App object, the App objects default constructor creates an instance of each of the manager and model classes.
    Sounds very sensible

    Quote Originally Posted by Nizars View Post
    Then in the main.cpp it gets pointers those that need to be set as context properties and the main sets them. the qml register types are also made in the App constructor.
    You don't really need to register any types, you are not creating instances of those classes in QML.

    I'd say your setup is quite ok, but if you are looking for an alternative then I would say

    1) set the App object as a context property
    2) make the other pointers accessible as Q_PROPERTY on the App object.

    But this is mostly cosmetic :-)

    Cheers,
    _

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

    Nizars (5th January 2017)

  9. #27
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,484
    Thanks
    252
    Thanked 712 Times in 702 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    An xml approach seems possible to but a bit easier.

    True, but not as easy as QSettings.
    Ah, but you can have it all! A while back I posted source code for a QSettings serializer that reads / writes QSettings to XML... It will take me a while to find that thread because it isn't tagged well enough for a simple search to pull it up.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. The following 2 users say thank you to d_stranz for this useful post:

    anda_skoa (5th January 2017), Nizars (5th January 2017)

  11. #28
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    I want to thank you guys again for all the help and directions. I really appreciate all the knowledge you have shared with me and all the directions you have provided me with. It would have probably taken me a month or so of trials and errors to figure out how to implement my classes to work with Qt QML. I have one more question by the way. A class mate has discussed with me an approach that can be used to integrate C++ with QML by creating something called a wrapper. Is this something you guys are familiar with? When is it usually usually appropriate to create Wrappers in Qt rather than designing the classes themselves in the Qt approach? And what are the benifits of taking that approach? I haven't found a lot of documentation on that approach and it didn't seem to be the easiest approach for an integrated front end and back end integration.

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

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Hmm, wrapper is a rather generic term, but I guess here is means a specialized class for the only purpose of bridging between QML and C++.
    I've written plenty of those.

    Sometimes to limit the API exposed to QML, e.g. wrapping a class that has many signals and slots but which you don't want QML to be able to connect to or call.
    Sometimes because the existing class is not a QObject, etc.

    Cheers,
    _

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

    Nizars (5th January 2017)

  14. #30
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,484
    Thanks
    252
    Thanked 712 Times in 702 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Here's the link to the QSettings / XML persistence thread, if interested.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  15. The following user says thank you to d_stranz for this useful post:

    Nizars (5th January 2017)

  16. #31
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    I have a question for you guys, why do I pass Card and Album objects to the model by value rather than by reference?
    I am referring to this line in the model:
    Qt Code:
    1. // albumcardsmodel.h
    2. protected:
    3. // Get the card object at the specified position in the Album
    4. Card cardForIndex(const QModelIndex &index) const;
    To copy to clipboard, switch view to plain text mode 

    I have been running into heap memory problems after adding a certain amount of cards, usually around 10 cards. I have been trying different things to see if I can do the neccessary improvements to my memory management. I am going to look into my destructors now.

  17. #32
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,484
    Thanks
    252
    Thanked 712 Times in 702 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    I have been running into heap memory problems after adding a certain amount of cards, usually around 10 cards.
    That seems symptomatic of a serious memory leak somewhere. What it sounds like to me is that you are making copies upon copies of each Card (and probably Album) everywhere. This is one of the main reasons why anda_skoa's design passed around card and album ids rather than Card or Album instances. What gets copied in that case is just the ID; there is only one instance of any particular Card, and that lives in the CardManager.

    why do I pass Card and Album objects to the model by value rather than by reference?
    In the case where "index" is invalid, what would you return if you passed by reference? You'd need a static "invalid Card" that you'd return a reference to. Again, this is why the model used IDs rather than Cards as the medium of communication between the various parts of the program.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  18. #33
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Quote Originally Posted by Nizars View Post
    I have a question for you guys, why do I pass Card and Album objects to the model by value rather than by reference?
    I am referring to this line in the model:
    Qt Code:
    1. // albumcardsmodel.h
    2. protected:
    3. // Get the card object at the specified position in the Album
    4. Card cardForIndex(const QModelIndex &index) const;
    To copy to clipboard, switch view to plain text mode 
    QModelIndex is passed via const reference, not by value.

    In case you are referring to the return value, then you could change that to const reference as well, but it won't make much difference, compilers usually optimize such "copy on return".

    Quote Originally Posted by Nizars View Post
    I have been running into heap memory problems after adding a certain amount of cards, usually around 10 cards.
    The card object in the example above is only transitory, there is only short time memory usage per call to data().

    I assume you've fixed all the memory leaks pointed out earlier?

    Quote Originally Posted by d_stranz View Post
    This is one of the main reasons why anda_skoa's design passed around card and album ids rather than Card or Album instances.
    That was mostly to avoid having copies of objects with outdated data.

    Quote Originally Posted by d_stranz View Post
    In the case where "index" is invalid, what would you return if you passed by reference? You'd need a static "invalid Card" that you'd return a reference to. Again, this is why the model used IDs rather than Cards as the medium of communication between the various parts of the program.
    This method is actually a signature I suggested

    It is an abstract lookup to allow for an immediate base class for card listing models. At some point the base class needs to get a card and that is the method it will invoke, implemented by each respective subclass. So it needs to return a Card object.

    Cheers,
    _

  19. #34
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Ok, I was able to solve the problem that happens after adding a certain number of Cards. I can now add as many cards as I want. The devil was in the details, I tried to follow the suggested methods on page 1 as close as possible and it worked immediately.

    The problem was with my AlbumsModel class, not the AlbumsCardsModel Class. I realized that I was doing something wrong there as it contained a QList<Album> that holds the Albums to show. I will try to find a suitable method.



    However, after adding any Card objects to the Album, I get the following error once I close the program:



    Once again, I suspect it's the destructor but I will have a look at everything again.

    There is also another problem that has been bugging the hell out of me. When I start debugging I immediately get the following warning:



    This is the line that triggers it in the disassembler:



    inspecting shows the following:





    C:\Windows\System32\spacedeskHookUmode.dll belongs to a software that I use to project my display to my laptop to use it as an extended display.
    I have no idea why the program cares for it or how to make it skip it or exclude it. The software I am using is from spacedesk.ph. Turning it off didn't do anything. I have also tried adding different arguments to the .pro file but with no luck.

  20. #35
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Edit: By the way, I have added network functionalities to the project. It now retrieves all the card data from an online Pokémon API and creates the Card objects from the retrieved json document. The images are also retrieved from an online source through https as well. I hade to add OpenSSL to the project. Disabling the retrieving of online data does not prevent the Debug Assertion error on closing the application. I am going through all my documents again trying to find the cause. Removing all the destructor definitions and declarations and leaving the job for the Qt magic didn't help either. The strange thing is that I don't get the error if I don't create any Cards which makes me believe that the problem happens when cards are created or sent to the model. Right now, there are no Card Objects in the Albums, they are all in the CardManager.

  21. #36
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Edit: Baam!! I found the source of the memory leak. It was the interaction between the QML addCard button and my App class. The button did something like this: app.getAlbumsManagerPointer()->addCard(albumID,cardID); The pointer it got wasn't managed properly by me. To find the source of the leak I had to comment out like 90% of my code in the project. I looked earlier in the thread and found the suggestion to make the AlbumsManager and CardsManager accessable through Q_PROPERTY(). Now, I have set two new read functions that return the pointers instead through the Q_PROPERTY. I don't really know why it makes a difference since I return pointers in both cases but I guess there is some memory management working here under the hood.

    It's now time to:

  22. #37
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    No more memory leaks! Here is how the program looks like right now:



    The reason there is a delay between adding a Card and seeing it on the screen is because I fetch the Card data through a network request and have to wait for the data to become ready. I am thinking about creating a dummy "empty card" with a rotating loading spinner that is temporarily displayed until the card is created or see if I can go about the whole thing in a different way that doesn't take as long. Here is how my addCard function looks like:

    Qt Code:
    1. // CardsManager
    2.  
    3. int CardsManager::addCard(const QString id)
    4. {
    5. // Request JSON for Card
    6. QString requestURL = "https://api.pokemontcg.io/v1/cards/";
    7. requestURL.append(id);
    8. m_networkManager.makeRequest(requestURL);
    9.  
    10. // Wait for response
    11. QEventLoop loop;
    12. connect(&m_networkManager, SIGNAL(qnamFinished()),&loop, SLOT(quit()));
    13. loop.exec();
    14.  
    15. // Open JSON document
    16. QString val = m_data;
    17. QJsonDocument jsonDocument = QJsonDocument::fromJson(val.toUtf8());
    18. QJsonObject rootObject = jsonDocument.object();
    19. QJsonValue value = rootObject.value(QString("card"));
    20. QJsonObject cardRootValues = value.toObject();
    21.  
    22. // Set values for card variables
    23. m_cardMID++;
    24. int cardMID = m_cardMID;
    25. QString name = cardRootValues.value("name").toString();
    26. QString cardId = cardRootValues.value("id").toString();
    27. QString subtype = cardRootValues.value("subtype").toString();
    28. QString supertype = cardRootValues.value("supertype").toString();
    29. QString nrString = cardRootValues.value("number").toString();
    30. int number = nrString.toInt();
    31. QString artist = cardRootValues.value("artist").toString();
    32. QString rarity = cardRootValues.value("rarity").toString();
    33. QString series = cardRootValues.value("series").toString();
    34. QString set = cardRootValues.value("set").toString();
    35. QString setCode = cardRootValues.value("setCode").toString();
    36. QString imageUrl = cardRootValues.value("imageUrl").toString();
    37. QString status = "Not specified";
    38. QString condition = "Not specified";
    39.  
    40. Card newCard(cardMID, cardId, name, imageUrl, subtype, supertype, number, artist, rarity, series, set, setCode, condition, status);
    41. this->m_cards << newCard;
    42.  
    43. // For debugging purposes
    44. qDebug() << "[CardsManager] Card: " << cardMID << cardId << name << imageUrl << subtype << supertype << number << artist << rarity << series << set << setCode << condition << status;
    45.  
    46. cardAdded(QString::number(cardMID));
    47. return cardMID;
    48. }
    To copy to clipboard, switch view to plain text mode 

    And here is my MainNetworkManager class:

    Qt Code:
    1. // MainNetworkManager
    2.  
    3. class MainNetworkManager: public QObject
    4. {
    5. Q_OBJECT
    6. public:
    7. explicit MainNetworkManager(QObject *parent = 0);
    8. void makeRequest(QString endpointRequest);
    9.  
    10. signals:
    11. void readyData(QByteArray);
    12. void qnamFinished();
    13.  
    14. public slots:
    15. void readReply(QNetworkReply *reply);
    16.  
    17. private:
    18. QNetworkAccessManager *qnam = new QNetworkAccessManager(this);
    19. };
    To copy to clipboard, switch view to plain text mode 

  23. #38
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    When you return a pointer to a QObject from an Q_INVOKABLE method or slot, then the QML engine will check if the object has a QObject parent.
    If it does not it assumes ownership of the pointer and deletes it in garbage collection.

    A pointer returned by a property is always owned by the object that holds the property.

    For the loading I would recommend an "asynchronous completion" approach.

    You add an empty or placeholder card when you make the request and attach the card identifier to the request.

    When the request ends, the slot that handles the response can then update the card's content.

    This will also require a signal in the card manager to notify about the card's content having changed, so that the models can emit their dataChanged() signals.

    Cheers,
    _

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

    Nizars (14th January 2017)

  25. #39
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    And BAMM! It's done!



    Next: I want to show a full-screen overlay when I click on a card. Basically, the Cards GridView will get dimmed and the Card that got clicked on fills part of the display. I want to, later on, add a data tree with information about the card and the ability to set its status and condition and have it display next to the Card in the full screen view. But that can wait for tomorrow, it's time to go out and have a few beers.

  26. #40
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Integration: Nested Tree Parent Child C++ Classes with Models/Delegates for QML

    Edit: No beers tonight, missed the train. It will have to wait till next weekend. But! I have fixed a command pattern for the network requests. I used a QSignalMaper and a QHash to map the different network replies to their requests. This way, I can quickly create a list of Cards without having the reply slots "overwritten" by the next request if it is made before the reply has completed.

Similar Threads

  1. Nested Models
    By Dan7 in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2015, 20:31
  2. Models and Delegates
    By bgeller in forum Newbie
    Replies: 13
    Last Post: 4th March 2010, 04:46
  3. QStandardItemModel, parent / child to form tree structure
    By Nightfox in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2010, 17:01
  4. Nested delegates in a QListWidget
    By youkai in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2009, 08:48
  5. Models, delegates or views and how?
    By maddogg in forum Newbie
    Replies: 3
    Last Post: 9th November 2007, 13:59

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.