Welcome! Log In Create A New Profile

Advanced

Assignment 2 Question 5

Posted by JohanB 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 2 Question 5
June 27, 2008 08:35AM
This question is starting to bug me.
Herewith some code, and the error messages I get for it:

My SortingAlgorithm.h:
Quote

#ifndef SORTINGALGORITHM_H
#define SORTINGALGORITHM_H

#include <QObject>

class SortingAlgorithm : public QObject
{
Q_OBJECT
public :
virtual QList<int> sort(QList<int> ) ;
// ~SortingAlgorithm();
};
#endif

My AbstractFactory.h;
Quote

class AbstractFactory
{
public:
virtual QList<int> createNewSortAlgorithm(QString sortType, QList<int> ) ;
// virtual ~AbstractFactory() ;
};

Everything seems to compile ok, but I get this:
undefined reference to 'vtable for AbstractFactory'
undefined reference to 'SortingAlgorithm::sort(QList<int> ) '

Any help would be most welcome. I was very tired when I wrote this code, so there may be some glaring mistakes...

Thanks in advance!
JB
Re: Assignment 2 Question 5
June 27, 2008 09:04AM
Make sure that you've saved everything in your IDE (including the project file) then close the IDE and open a command prompt to your project folder and run "qmake -project" (maybe a few times for good measure)
Re: Assignment 2 Question 5
June 27, 2008 09:07AM
stevenv,

I'll try that tonight. I did close the IDE, opened it up again, and rebuilt my project, but to no avail.
Having to deal with a buggy IDE is not something I enjoy dealing with right now...

Cool, thanks!
JB
Re: Assignment 2 Question 5
June 30, 2008 07:37PM
Its not an IDE issue.
If you get a undefined reference to vtable error it usually means you forgot a ; after the closing brace of one of your class definitions.
the second error you get ... did you implement the function?
Anonymous User
Re: Assignment 2 Question 5
June 30, 2008 08:39PM
Why is QObject neccessary here?
Re: Assignment 2 Question 5
July 02, 2008 08:29AM
I was sick for a couple of days.
The vtable error went away when I added "= 0;" to all my virtual function definitions.
So the IDE was not to blame. My bad, I'm sorry.

QObject is not necessary, you're right. Thanks.

I'm more or less healthy again, so by tomorrow I'll probably have some more stupid questions...

Cheers, all!
JB
Re: Assignment 2 Question 5
July 03, 2008 07:32AM
virtual QList<int> createNewSortAlgorithm(QString sortType, QList<int> ) ;


Where is the QList<int> variable name? i.e.
virtual QList<int> createNewSortAlgorithm(QString sortType, QList<int> items) ;
Re: Assignment 2 Question 5
July 03, 2008 03:05PM
sanjivdo Wrote:
-------------------------------------------------------
> virtual QList createNewSortAlgorithm(QString
> sortType, QList ) ;
>
>
> Where is the QList variable name? i.e.
> virtual QList createNewSortAlgorithm(QString
> sortType, QList items) ;

You actually don't need to specify formal parameters names in your class declaration (since you will be specifying them in your member function implementation - this is the only possible place you are concerned with the parameter name)
Re: Assignment 2 Question 5
July 04, 2008 04:00PM
Anyone else stuggling with the Model/View stuff?
Re: Assignment 2 Question 5
July 06, 2008 09:47AM
I am.

I used the code directly from the help files and it doesn't compile. I asked one of the lecturers for some help with this, but she never replied.

JoJ.
Re: Assignment 2 Question 5
July 06, 2008 03:02PM
QListView* listView = new QListView(this);
QStringList sortedItems;
QStringListModel* model = new QStringListModel(sortedItems);
listView->setModel(model);
Re: Assignment 2 Question 5
July 06, 2008 03:54PM
Apologies to the lecturer, because she did reply. It got sent to my junk mail folder for some inexplicable reason.

JoJ.
Re: Assignment 2 Question 5
July 06, 2008 06:13PM
This may be a bit late, but hope it helps some of you:


The Model/View Programming may be a bit tough to comprehend without simple examples which seems difficult to find at first.

Very briefly:
Model: Accesses underlying data and provides an interface to it.
View: Uses the Model to display information and interact with it (ie, selecting a treeview item)

Where to Start ?
Qt4 Provide basic Models you can use, they are documented in the Qt Assistant
under the topic "Item View Convenience Classes" in the "Reference Documentation", under Overviews.


This doesn't really apply to Assignment 2 Question 5, because it doesn't use the QListView.


Quoting from the "Model/View Programming" page:

Qt provides some ready-made models that can be used to handle items of data:
* QStringListModel is used to store a simple list of QString items.
* QStandardItemModel manages more complex tree structures of items, each of which can contain arbitrary data.
* QDirModel provides information about files and directories in the local filing system.
* QSqlQueryModel, QSqlTableModel, and QSqlRelationalTableModel are used to access databases using model/view conventions.



Read the QStringListModel documentation, there's a simple example which can be modified as follows to use the QListView class:

QStringListModel *model = new QStringListModel();
QStringList list;
list << "a" << "b" << "c";
model->setStringList(list);

QListView *lv = new QListView();
lv->setModel(model);




In the same way that QStringListModel can be used to display a QListView,
QStandardItemModel can be used to create tables and trees.

-- Ipsa Scientia Potestas Est
Re: Assignment 2 Question 5
July 06, 2008 06:15PM
ah, only saw stevenv's post now which listed the same as my previous post
Re: Assignment 2 Question 5
July 10, 2008 12:21AM
Johan, just a question on the following code you posted:

Quote

class AbstractFactory {
public:
virtual QList<int> createNewSortAlgorithm(QString sortType, QList<int> ) ;
virtual ~AbstractFactory() ;
};



Why is the return type of your createNewSortAlgorithm method a QList<int> ?

My understanding of the abstract factory is that you will create the related objects from it, without specifying the concrete class. So should we not return the object that is created, rather than the return type of the sort method ? ...

Example:
Quote

class AbstractFactory {
public:
virtual [color=#FF0000

SortingAlgorithm*[/color] createNewSortAlgorithm(QString sortType) ;
virtual ~AbstractFactory() {}
};
]

Or am I just misinterpreting the pattern or missing something ?

PS: I'm still on this question 4, is there still hope of completing the assignment before the 14th ?
Re: Assignment 2 Question 5
July 10, 2008 09:00AM
Esckay,

From ex 16.1 in the textbook:
[...]
class AbstractFactory {
public:
virtual DataObject* newObject (QString className) = 0;
virtual ~AbstractFactory() {}
[...]
class ObjectFactory : public QObject, public AbstractFactory {
Q_OBJECT
public:
static ObjectFactory* instance() ;
virtual DataObject* newObject (QString className);
Address* newAddress (Country::CountryType country =
Country::Undefined);
Address* newAddress (QString countryName = "USA"winking smiley;
protected:
ObjectFactory() {}
};
[...]

I took DataObject to be whatever the output of the concrete factory should be, but I may be wrong.
Anyone else??

I am thinking of leaving out Q4, but all the rest is done. How much work is Q4, really?
Once you have Q5 waxed, Q7 is a walk in the park, & Q6 is not all that much work, if I remember correctly.

Cheers,
JB
Re: Assignment 2 Question 5
July 10, 2008 11:07AM
Sorry, I meant that I'm on question 5. I still need to finsish this and then 6 + 7. The rest is done.

Question 4 is not that much, but it took me a while to figure out some intracacies there.

"I took DataObject to be whatever the output of the concrete factory should be" - but shouldn't the output of the concrete factory be the object that is create and not the output of a method of the object ?

Anyone, could you please clear this up?

Johan, I am not say you are incorrect, I would just like clarity because I ran into a simliar issue on assignment 1 and I had to go and redo the whole question because my interpretation was incorrect and I really dont want do that again.
Re: Assignment 2 Question 5
July 10, 2008 08:26PM
Anyone ?

A bit of guidance please ?
Re: Assignment 2 Question 5
July 10, 2008 08:29PM
The question also states:

"The factory method should use a QString as an input parameter to determine the correct concrete class"

... but it doesn't say that it should be the only parameter ...
Re: Assignment 2 Question 5
July 10, 2008 08:34PM
O, and ....

"The next step is to implement the Abstract factory design pattern so that its factory method returns a reference to the correct concrete sorting class."
Re: Assignment 2 Question 5
July 11, 2008 12:01AM
Yes, me again ....

Can anyone help me ? I think I'm a bit lost on this question.

I have completed the abstract factory part of the question, but the model/view interface is screwing me around.

Here is what I have so far:
myUI.h + myUI.cpp: My user interface is done here to get the input (the unsorted list and the sorting algorithm)

Now here is what I don't get:
Should we have a seperate class where the QListView is done or should it be part of the user interface ?

The following code was posted here:
QListView* listView = new QListView(this);
QStringList sortedItems;
QStringListModel* model = new QStringListModel(sortedItems);
listView->setModel(model);

Now where the hell do I use this code?
Sorry, only registered users may post in this forum.

Click here to login