Skip to main content

Some Qt and C++ tickles for UNISA COS2614

Qt software
Some simple things to remember for the UNISA COS2614 exam, in no particular order:

Download Qt here: https://www.qt.io/download/

Nice simple Qt examples here: http://zetcode.com/gui/qt4/


C++ if-else shorthand (ternary operators): 
condition ? value_if_true : value_if_false

Command Line Arguments: 
int main ( int argc, char *argv[] )
The integer, argc is the ARGument Count (hence argc). It is the number of arguments passed into the program from the command line, including the name of the program.

The array of character pointers is the listing of all the arguments. argv[0] is the name of the program, or an empty string if the name is not available. After that, every element number less than argc is a command line argument. You can use each argv element just like a string, or use argv as a two dimensional array. argv[argc] is a null pointer.

Explain two benefits of applying design patterns in OOP:
Improves re-usability and extensibility of software.
  • Re-usability - want to be able to re-use relevant bits of code in the simplest way possible. Design patterns attempt to express similar code in an abstract way, this allows for code reuse. We are able to design abstract classes in a way that allows us to derive from these classes and use similar code, this promotes code reusability.
  • Extensibility - how easy is it to add enhancements to an app. Design patterns also promote extensibility. A measure of how easy it is to add improvements to an application and one way of making code extensibility is to provide classes which can easily be sub-classed. Qt framework is a good example of this.

explicit:

The keyword explicit can be placed before a single argument constructor in the class
definition to prevent automatic conversion from being used by the compiler. This is useful if the argument is not anything like the class it is constructing, or if there is something akin to a parent-child relationship between them.
Classes generated by QtCreator place this keyword before the generated custom widget constructors, and it is advisable that you do the same with your QWidget -derived classes.
(The keyword explicit prevents the compiler from automatically using that constructor for implicit type conversions.)

Stack and Heap stuff:
When QObjects are created with new, they are created on the heap.
Otherwise they are created on the stack.

Polymorphic Assignment:
Polymorphic assignment allows a pointer of type superclass to point to objects of its concrete subclasses.

QMessageBox: 
QMessageBox::information (0, "String Reverse", reversed);

Very Simple Random number generator:
#include
#include

int main()
{
QTextStream cout(stdout);

qsrand(QTime::currentTime().msec());
int random = qrand() % 5;
cout << "Random number: " << random << endl;

return 0;
}

Very simple SIGNALS and SLOTS example:
//include necessary pre-processor directives here

int main(int argc, char *argv[]){
QApplication a(argc, argv);
QWidget w;
QLabel *label = new QLabel("Enter Text:");
QLineEdit *input = new QLineEdit("Hello");
QPushButton *clear = new QPushButton("Clear");
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(label);
layout->addWidget(input);
layout->addWidget(clear);
w.setLayout(layout);
QObject::connect(clear, SIGNAL(clicked()), input, SLOT(clear()));
w.show();
return a.exec();
}

What is the difference between a function declaration and a function
definition?
A function declaration describes how a function can be called.
A function definition includes the actual code that is to be executed.


Popular posts from this blog

How to create a mirror with 3ds max and V-Ray

Creating a mirror with 3ds Max and V-Ray

In this tutorial we will create a simple, framed mirror with 3ds Max. We will then create the V-Ray materials for this mirror, and finally we will render out a simple 3d scene, showing reflections in the mirror.

I am assuming that you have a basic knowledge of 3ds Max, so I won't explain absolutely everything, but it should still be easy enough for beginners to figure out what is going on in this tutorial.

Step 1
Creating the mirror surface. Create a box in the front viewport that is approximately 70cm x 40cm x 0.4cm (Note, it doesn't have to be exactly this size and if you would prefer to work in inches or other units, that's also okay, I'm just used to working in cm.)


Step 2
Create the actual V-Ray mirror material. Open up the material editor and change the first material in the material editor to a VrayMtl.



Rename this material "mirror surface" and make it totally reflective, by making the reflect color swatch totall…

Tutorial: How to make a shadow matte with V-Ray

Welcome to this tutorial on making a shadow matte with V-Ray. To complete this tutorial you will need 3DS Max 2008 or newer, with V-Ray 1.5 and Adobe Photoshop.

The purpose of this tutorial is to show you how to render out a 3D object, with its shadow included in an alpha channel, so that you can composite the 3D object and it's shadow on top of an existing photograph.

You will need to download the "vray shadow matte tutorial.rar" file from: http://www.turbosquid.com/FullPreview/Index.cfm/ID/473854

In this file you will find two 3ds max files, a background photo and some additional info.
Please note that the max file used in this tutorial uses the V-Ray LWF (Linear Work Flow) technique, as described on the chaosgroup forums (www.chaosgroup.com). To use LWF you need to change 3DS Max's Gamma settings - please see the included file called "LWF_gamma_settings.jpg" to see what your settings should be. (You can change the Gamma settings in 3DS Max under: Customi…

How to create a wireframe material with V-Ray

Welcome to this tutorial on making a wireframe material with V-Ray. To complete this tutorial you will need 3DS Max with V-Ray.

Step 1
The fist thing we need to do is create an object that we will apply our wireframe material to, in my case I made a simple teapot. Add a camera to the scene too.

Step 2
Create a normal V-Ray material. (Open up the material editor and change the first material in the material editor to a VrayMtl). Rename this material "wireframe"

Step 3
Add a map to the diffuse channel of the material (by clicking the little square box next to the diffuse colour swatch). Choose the VRayEdgesTex map.

Step 4
You will notice that the default colour for the VRayEdgesTex map is white. (This means the wires of the wireframe material will be white. You can change it to any colour you like, but let us leave it as white for now. Notice too that you can change the thickness/units of the VRayEdgesTex map and that you can choose to show the hidden edges too. (triangular faces…