Welcome! Log In Create A New Profile

Advanced

COS211-X -> COS311-4

Posted by Moonfruit 
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
COS211-X -> COS311-4
April 04, 2007 09:57AM
Hi there

Firstly, I would like to make it clear that I understand and have no problem with the fact that COS311-4 is a high-level module on advanced program and, as such, can be very complicated.

However, am I the only one who thinks that the leap between the material covered in COS211-X (I used Malik's book "Data Structures Using C++" last year) and the material in this module is just a little too big? I find that most of what I learned about C++ is pretty much useless.

Not only that, but the textbook (Ezust & Ezust) itself can be hard to understand as well. The first 6 chapters are supposed to provide a basic C++ knowledge, but even I had a hard time understanding things. Every time it introduces a new concept, it jumps straight into it with a complex example instead of a basic one to make you comfortable with the concept.

Furthermore, I find that the textbook and tutorial letters are not exactly clear on the software one must use and how to go about doing it, and one must muddle your way through until you figure it out.

Perhaps there's something I'm missing, but I find I'm spending more time trying to understand the textbook and what exactly the Ezust family is saying, than actual programming.

Overall, I am a little disappointed in the lack of clarity in this module.
avatar Re: COS211-X -> COS311-4
April 04, 2007 10:33AM
Understand the the core of this course is to learn Design Patterns. The added complexity of Qt4 doesn't help much although it is nice that there's a better API than Cohoon's EzWindows (*curse* *splutter*)

Are there any specific problems you're having?
Re: COS211-X -> COS311-4
April 04, 2007 10:55AM
I do understand that, but I think that UNISA approached the topic incorrectly. A lot of the students here are relatively "new" to C++ in the sense that the only experience we've had is through previous UNISA modules (i.e. COS111, 112 and 211).

With this module, however, they attempt to do 2 things at once: (1) introduce us to the more complex concepts of C++ (including design patterns), as well as (2) introduce us to Qt4.

Both of these can be difficult individually, and I feel that it might have been better to have a separate course for each, instead of cramming everything into one.

As for specific problems...

I'm having a bit of a hard time understanding everything where Qt4 is involved, but only because of the haphazard way in which Ezust goes about explaining them.

I cannot get QIde to run (something about not being able to find QtCore4.dll), if I use the qstd namespace (like in the textbook) my programs won't compile...and several more I cannot think of now.

Also, there is never really an explanation for compiling on a Windows platform. I've never been able to get an .o file (all of mine of automatically been .exe, even without the -o switch).

All in all, I get the impression that this subject takes on a "jack of all trades, master of none" approach to C++ in the way it explains a little bit of everything, but never enough to really help you understand what you're doing.

Chapter 3 is a perfect example of this. You're told to write the program and such, but each new thing that's introduced is never really explained.

Programming should be about explanation and sufficient examples and exercises ( from easy to difficult) to help you understand.
avatar Re: COS211-X -> COS311-4
April 04, 2007 11:49AM
If you can't get QIde to work, start all over again. Uninstall QIde (ie delete it). Uninstall Qt4, devc++ and mingw.

Follow the instructions under COS112 on the CD for the installation of MinGW and DevC++, then follow the instructions under COS311 for the installation of Qt4 and QIde. Do NOT use a downloaded version of any of the programs, always use the ones on the CD, and go slowly (like you're a complete idiot and have never done it a million times before). You'll probably find you skipped something by accident.

Then follow the instructions in tut102 for the installation of Ezust's libraries (needed for qstd.h etc)
avatar Re: COS211-X -> COS311-4
April 04, 2007 11:51AM
I hope you did COS214 last year since it introduced a few of the simpler design patterns. I find they're great since they teach you to split your program into specialised classes instead of, "this class does this, oh, and it needs to do this and this as well"
avatar Re: COS211-X -> COS311-4
April 04, 2007 11:58AM
As far as QIde is concerned, I hate it. It's buggy and gdb is a rather useless debugger. I'm still trying to figure out how to port the whole framework so I can program on MS Visual Studio.

The first thing I have to do is figure out the structure of all the projects and recreate them so I can compile the libraries. Secondly, I need to figure out how to get the moc thingy to work. I think this is the stupidest invention in Qt. Why couldn't they use plain old C++ so you can use any IDE. Nope, they couldn't do that, they had to invent extra parts of the c++ language (signals, slots and foreach) so that it has to be converted to standard c++ before being compiled.

That's the reason you have to do a qmake before doing a make. It's a precompile before compiling, and also the reason you can't program directly in DevC++.
Re: COS211-X -> COS311-4
April 04, 2007 11:43PM
robanaurochs Wrote:
-------------------------------------------------------
> As far as QIde is concerned, I hate it. It's buggy
> and gdb is a rather useless debugger. I'm still
> trying to figure out how to port the whole
> framework so I can program on MS Visual Studio.
>
> The first thing I have to do is figure out the
> structure of all the projects and recreate them so
> I can compile the libraries. Secondly, I need to
> figure out how to get the moc thingy to work. I
> think this is the stupidest invention in Qt. Why
> couldn't they use plain old C++ so you can use any
> IDE. Nope, they couldn't do that, they had to
> invent extra parts of the c++ language (signals,
> slots and foreach) so that it has to be converted
> to standard c++ before being compiled.
>
> That's the reason you have to do a qmake before
> doing a make. It's a precompile before compiling,
> and also the reason you can't program directly in
> DevC++.


Ermmm yeah well Visual Studio is commercial and QIde is open source. You get what you pay for .. and if you aren't happy with QIde - get a refund winking smiley.Qt licensing model: Qt free/GPL version is for the GNU C/ MingW toolchain; Qt commercial is for Visual Studio. So in a nutshell if you are prepared to pay around $7500 ($2500 for VS.NET + $5000 for Qt4 commercial) you can use Visual Studio.NET as an IDE for Qt. A final comment- Qt's steep learning is more than compensated by its power and flexibility: can you port an MFC application to Linux/Solaris/AIX etc etc ... with little or no code re-write? I think not.

Qt's objective is to achieve minimal code re-write, so its closest rival would be Java (write once, run anywhere). If you are looking at it from a technical perspective: Java class files run over the Java VM; Qt source code can be compiled into a native executable format, Qt wins hands down in performance!

Hope that clears some doubt.

Regards
Re: COS211-X -> COS311-4
April 05, 2007 11:35AM
Thanks for the replies thus far. I've managed to narrow my problems down to a few specifics now smiling smiley

First off, a little bit about my software and settings:

I have installed all my files from the UNISA CD precisely as instructed; going through it slowly, in a central folder "C:\UNISA", which now contains the following directories:

DevCPP (for COS111, 112 and 211, don't use it this year though)
Ezust_Utils
MinGW (version 3.4.2 off the 2007 disk)
Qt (contains the subfolders 4.1.1 and QIde-0.19)

I edited the supplied QIde batch file to include the correct path, and now I can get it to run (but only when working on a project, not on individual files sad smiley )

To write my programs, I use a purchased version of JGSoft's EditPad Pro 6 with built in C++ syntax colouring and a few other nice tweaks smiling smiley

All of my source code that I write is placed in "My Documents\UNISA\2007\COS311-4", and my Qt 4.1.1 Command Prompt path has been edited to match that.

Also, I use Windows XP.

Anyway, that’s the basis for my setup. Now onto my problems tongue sticking out smiley

Whenever I try to run a program using Qt (i.e. anything that uses #include<QString>, <QDebug>, etc, or the qstd namespace) it tells me the files don't exist. I'm guessing that this has something to do with incorrect path setups somewhere, but I'm not sure where.

In case there's something I missed, I'll attach my source code here, as well as the output. It’s from examples 10.3, 10.4 and 10.5 in the textbook.

Stack.h

#include <qstd>

template<class T> class Node {
public:
Node(T invalue): m_Value(invalue), m_Next(0) {}
~Node();
T getValue() const {return m_Value;}
void setValue(T value) {m_Value = value;}
Node<T>* getNext() const {return m_Next;}
void setNext(Node<T> *next) {m_Next = next;}
private:
T m_Value;
Node<T> *m_Next;
};

template<class T> Node<T>::~Node() {
using namespace qstd;
cout << m_Value << " deleted" << endl;
if(m_Next) {
delete m_Next;
}
}

template<class T> class Stack {
public:
Stack() : m_Head(0), m_Count(0) {}
~Stack<T>() {delete m_Head;}
void push(const T& t);
T pop();
T top() const;
int count() const;
private:
Node<T> *m_Head;
int m_Count;
};

template<class T> void Stack<T>::push(const T& value) {
Node<T> *newNode = new Node<T>(value);
newNode->setNext(m_Head);
m_Head = newNode;
++m_Count;
}

template<class T> T Stack<T>::pop() {
Node<T> *popped = m_Head;
if(m_Head != 0) {
m_Head = m_Head->getNext();
T retval = popped->getValue();
popped->setNext(0);
delete popped;
--m_Count;
return retval;
}
}

/* I added the implementations of these two myself, since they're not in the
textbook. Don't think it makes a difference though.
*/


template<class T> T Stack<T>::top() const {
return m_Head->getValue();
}

template<class T> int Stack<T>::count() const {
return m_Count;
}

main.cpp

#include <QDebug>
#include <QString>
#include "stack.h"

int main() {
Stack<int> intstack1, intstack2;
int val;

for(val = 0; val < 4; ++val) {
intstack1.push(val);
intstack2.push(2 * val);
}

while(intstack1.count()) {
val = intstack1.pop();
qDebug() << val;
}

Stack<QString> stringstack;
stringstack.push("First on"winking smiley;
stringstack.push("second on"winking smiley;
stringstack.push("first off"winking smiley;
QString val2;

while(stringstack.count()) {
val2 = stringstack.pop();
qDebug() << val2;
}

qDebug() << "Now intstack2 will self destruct.";

return 0;
}

Messages in DOS prompt when trying to compile using the command g++ -ansi -pedantic -Wall -o main.exe main.cpp

main.cpp:1:18: QDebug: No such file or directory
main.cpp:2:19: QString: No such file or directory
In file included from main.cpp:3:
stack.h:1:16: qstd: No such file or directory
In file included from main.cpp:3:
stack.h: In destructor `Node<T>::~Node()':
stack.h:17: error: expected namespace-name before ';' token
stack.h:18: error: `cout' undeclared (first use this function)
stack.h:18: error: (Each undeclared identifier is reported only once for each fu
nction it appears in.)
stack.h:18: error: `endl' undeclared (first use this function)
main.cpp: In function `int main()':
main.cpp:16: error: `qDebug' undeclared (first use this function)
main.cpp:19: error: `QString' undeclared (first use this function)
main.cpp:19: error: template argument 1 is invalid
main.cpp:19: error: invalid type in declaration before ';' token
main.cpp:20: error: `push' has not been declared
main.cpp:20: error: request for member of non-aggregate type before '(' token
main.cpp:21: error: `push' has not been declared
main.cpp:21: error: request for member of non-aggregate type before '(' token
main.cpp:22: error: `push' has not been declared
main.cpp:22: error: request for member of non-aggregate type before '(' token
main.cpp:23: error: expected `;' before "val2"
main.cpp:25: error: `count' has not been declared
main.cpp:25: error: request for member of non-aggregate type before '(' token
main.cpp:26: error: `val2' undeclared (first use this function)
main.cpp:26: error: `pop' has not been declared
main.cpp:26: error: request for member of non-aggregate type before '(' token
stack.h: In destructor `Node<T>::~Node() [with T = int]':
stack.h:27: instantiated from `Stack<T>::~Stack() [with T = int]'
main.cpp:6: instantiated from here
stack.h:17: error: `<type error>' is not a namespace

Anyone got any advice please?
avatar Re: COS211-X -> COS311-4
April 05, 2007 12:09PM
In the tut02 letter that shows you how to set up the Ezust libraries is a section used to test that they're working. Part of the section describes how to set up the example project to use the INCLUDEPATH etc. variables. That whole section must be carried out FOR EVERY PROJECT that you do in QIde. There is no way that I know of where you can start a project (ie. with project template like in DevC++) with those settings already entered.
Re: COS211-X -> COS311-4
April 05, 2007 12:16PM
OK, that makes sense I guess. Are you saying that I need to use QIde to write the source code for this example then?

Also how does one know what program to use for each project? For example, how do you know when to use QIde and when to use a plain text editor with the g++ command line to compile?

UNISA doesn't make it very clear when you're supposed to use what sad smiley
Re: COS211-X -> COS311-4
April 05, 2007 01:26PM
There is a way to start projects with all the info already entered...I think tongue sticking out smiley

What I have done is create a new text file and renamed it "template.pro", with the following code in it:

CONFIGURE += Qt
INCLUDEPATH += $$(CPPLIBS)/utils
LIBS += -L$$(CPPLIBS) \
-lutils
# HEADERS +=
# SOURCES +=

Then you just copy this file into each project directory, rename it, uncomment and add the appropriate headers(s) and source(s), and there you go. When you open it up in QIde, all the variables and values are in the project.

So correct me if I'm wrong here...

(1) If a project uses your standard C++ things (i.e. everything EXCEPT Qt stuff), you can write it normally and compile it in any compiler or using the g++ command.

(2) If it does use anything Qt-related, you have to create a project file for it, and then use either QIde to build and execute it, or the qmake and make command line options.

Does that sound about right? Or did I miss something again?
avatar Re: COS211-X -> COS311-4
April 05, 2007 02:18PM
Your two suppositions are correct.

Qt4 has added some "extra" keywords to the c++ language (signal, slot and foreach are not part of standard c++) that the standard compilers won't understand properly. When you use qmake, it runs the moc translator. That goes through all of your source code looking for these new keywords and creates extra code to add to your project.

If you look in your directories, you'll not only see your own object files (.o) but also files starting with moc_ this is the extra code that gets added. Once this code is generated, it and your code gets handed over to the standard compiler for final compilation.
Anonymous User
Re: COS211-X -> COS311-4
April 05, 2007 09:08PM
For a layman's clarification of c, c++, Qt and just about anything, why not use Wikipedia
Re: COS211-X -> COS311-4
April 06, 2007 07:31PM
This is one of the modules keeping me awake at night...
Sorry, only registered users may post in this forum.

Click here to login