Results 1 to 18 of 18

Thread: Modification of a question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2013
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Modification of a question

    Hi there once again, thank you for the info from those two sites on QMaps and QLists. I understand the differences and concepts much better now after reading that info together with stuff on google. I didn't want to come back and post without attempting any solution to original posted question because that would mean I did not learn anything from the stuff I read. below is some code I wrote, consisting of my understanding of what the header and source file should look like, please check it and correct me if I misunderstood or am doing this incorrectly.

    below is my header file:

    Qt Code:
    1. #ifndef FILM_H
    2. #define FILM_H
    3.  
    4. #include <QObject>
    5. #include <QString>
    6. #include <QMap>
    7.  
    8. class Film : public QObject
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13.  
    14. Film (QString id, QString title, QString dir, QString length, QDate relDate);
    15. Film (QStringList propList);
    16. QString virtual toString (bool labelled, QString sepChar);
    17.  
    18. private:
    19.  
    20. QString m_FilmId;
    21. QString m_Title;
    22. QString m_Director;
    23. QString m_FilmLength;
    24. QDate m_ReleaseDate;
    25.  
    26. };
    27.  
    28. //Managed collection of pointers
    29.  
    30. class FilmMap : public QMap<QString, Film*>
    31. {
    32. public:
    33.  
    34. QString toString() const;
    35. Film* findFilm (QString id);
    36. QString getId (QString title);
    37. void addFilm (Film* film);
    38. void removeFilm (QString filmId);
    39.  
    40. };
    41.  
    42. #endif
    To copy to clipboard, switch view to plain text mode 



    Below is my implementation file:

    Qt Code:
    1. #include <QMap>
    2. #include <QMapIterator>
    3. #include "film.h"
    4.  
    5. using namespace std;
    6.  
    7. QString FilmMap :: toString () const
    8. {
    9. QString retval;
    10. QTextStream os(&retval);
    11. ConstIterator itr = constBegin();
    12. for (; itr != constEnd(); ++itr)
    13. os << '[' <<itr.key() << ']' << ":"
    14. << itr.value() -> toString() << endl;
    15. return retval;
    16. }
    17.  
    18. Film* FilmMap :: findFilm (QString id)
    19. {
    20.  
    21. }
    22.  
    23. QString FilmMap :: getId (QString title)
    24. {
    25. return Id;
    26. }
    27.  
    28. void FilmMap :: addFilm(Film* film)
    29. {
    30. insert (film -> getId(), film);
    31. }
    32.  
    33. void FilmMap :: removeFilm (QString filmId)
    34. {
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 



    I have coded what I understood of the question but I do not know how to implement the 'findFilm' and 'removeFilm' iterators, kindly advise me on this please and tell me if I have done the above correctly. I would also appreciate if you could tell me hoe I code the main function in order to test the functions in FilmMap. Thank you so much for all your assistance.
    Last edited by R.ANGEL; 29th August 2013 at 18:49.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Modification of a question

    Quote Originally Posted by R.ANGEL View Post
    I didn't want to come back and post without attempting any solution to original posted question because that would mean I did not learn anything from the stuff I read.
    Now that's a great attitude! Congratulations!

    Before we get into lists and maps, please try to think whether you really need Film to inherit QObject and if not, whether you need the map to hold pointers to Film instances instead of just Film instances (i.e. QMap<int,Film> and not QMap<int,Film*>).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2013
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Modification of a question

    good morning

    I need the map to hold pointers to film instances such as:

    QMap<int, Film*>

    in my opinion from reading the question.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Modification of a question

    Why do you need pointers?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2013
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Modification of a question

    I thought that since inheritance was occurring we would need to use pointers.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Modification of a question

    Quote Originally Posted by R.ANGEL View Post
    I thought that since inheritance was occurring we would need to use pointers.
    Inheritance itself has nothing to do with this. Only if you inherit QObject you need to use pointers because QObject instances can't be copied. But your class does not require QObject legacy, thus my original question.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2013
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Modification of a question

    so I guess I have been attempting this solution the incorrect way by inheriting QObject and using pointers

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Modification of a question

    It is not that it is incorrect, it's just more difficult and simply not required. I suggest you KISS.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Aug 2013
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Modification of a question

    I am unsure on how to proceed next in completing my solution though

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Modification of a question

    Remove QObject legacy, change the map definition and implement functions for adding film instances to the map, removing them, etc.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Aug 2013
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Modification of a question

    ok thank you Sir, I will attempt that and repost my solution

Similar Threads

  1. modification to pictureflow widget
    By qtnewbi3 in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2011, 15:47
  2. Layout modification in QListWidget
    By ouekah in forum Newbie
    Replies: 2
    Last Post: 20th March 2010, 07:15
  3. QStandardItem color modification
    By prashant in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2009, 10:24
  4. file modification date/time
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2009, 21:43
  5. modification time on files
    By soul_rebel in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 21:51

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
  •  
Qt is a trademark of The Qt Company.