Results 1 to 18 of 18

Thread: Modification of a question

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

    Default Modification of a question

    HI THERE,

    I AM 46 AND PRETTY NEW TO LEARNING ABOUT QT USING C++ SO PARDON ME IF IM A LITTLE SLOW IN PROGRESSING

    I HAVE PURCHASED THE TEXTBOOK CALLED "AN INTRODUCTION TO DESIGN PATTERNS IN C++ WITH Qt" AND I WANTED TO STUDY THIS BOOK PROPERLY AND UNDERSTAND AND PROGRAM THE EXERCISES BEFORE TAKING UP A COURSE NEXT YEAR WHICH CAN TEACH ME THE MORE COMPLEX STUFF ABOUT THIS PROGRAMMING CONCEPTS. I HAVE BEEN COPING WELL WITH THE EXERCISES THUS FAR AND HAVE BEEN PRODUCING THE REQUIRED OUTPUTS BUT I WOULD LIKE TO KNOW HOW I CAN MODIFY THE ATTACHED PDF QUESTION(FROM THE TEXTBOOK) :

    SO THAT FilmList is replaced by the class FilmMap, which inherits from QMap<QString, Film*> where the film id is the key. I want to re-implement all the functions in FilmList in FilmMap.

    how do I do this and how do I write my code to test FilmMap and all its functions.

    Please assist as I am very new to this and am studying this book completely for my own indulgement without any help.
    I have attached the textbook question on which I base my question
    Attached Files Attached Files

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

    Default Re: Modification of a question

    does anyone have any knowledge on how to do this, I feel helpless

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

    Default Re: Modification of a question

    What exactly are you having problems with? All you need to do is to adjust the code from operating on QList to operating on QMap.
    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.


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

    Default Re: Modification of a question

    I don't know how to do that though. I have been doing very simple programs so far and I am now moving on to these more complex program, or rather complex for me since I am doing this without guidance. a start would be good please. I am in no rush since I am just playing around with the programs and trying to complete all the textbook examples without looking at the manual answers.

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

    Default Re: Modification of a question

    Do you understand what are the main differences between a list and a map?
    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.


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

    Default Re: Modification of a question

    to be honest I don't, but I am using google and other sites to gain as much knowledge on this. any help is greatly appreciated please.

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

    Default Re: Modification of a question

    Quote Originally Posted by R.ANGEL View Post
    to be honest I don't, but I am using google and other sites to gain as much knowledge on this.
    Great. Come back when you have gained this knowledge. Without it there is no way to progress.

    Here is something to get you going:

    http://www.cplusplus.com/reference/map/map/
    http://www.cplusplus.com/reference/list/list/
    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.


  8. #8
    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 17:49.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


  10. #10
    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.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


  12. #12
    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.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


  14. #14
    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

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


  16. #16
    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

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


  18. #18
    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, 14:47
  2. Layout modification in QListWidget
    By ouekah in forum Newbie
    Replies: 2
    Last Post: 20th March 2010, 06:15
  3. QStandardItem color modification
    By prashant in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2009, 09:24
  4. file modification date/time
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2009, 20:43
  5. modification time on files
    By soul_rebel in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 20: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.