PARP Research Group Universidad de Murcia

Hello world

As any other Qt-based application, QVision applications are created from Qt projects. A Qt project file specifies the source files and requirements necessary to create any Qt application. The following is the content of an example Qt project file. The project will contain a single C++ source file named example.cpp:

TARGET = example
SOURCES = example.cpp

The project file of any QVision application must include the file qvproject.pri. This file can be found at the QVision library path. It contains the setup for the qmake tool to compile applications with the QVision.

The line TARGET = example in our .pro example file sets the name of the application's executable to example. TARGET is a reserved variable name that should contain the name of the executable objective of the compilation. The variable SOURCES must contain a space separated list of the source files of the application. In our example, the project has only one source file named example.cpp.

We can store the previous project file with the name along with the source file example.cpp described below, which will contain the source code of our hello-world application.

Source code for the 'example.cpp' file

We can insert the following code in the example.cpp file:

#include <iostream>
#include <qvimageio.h>

int main(int argc, char *argv[])
        // Check if the user provided enough command line parameters.
        if (argc < 3)
                std::cout << "Usage: " << argv[0] << " <input image> <output image>" << std::endl;
                return -1;

        // Input and output images
        QVImage<uChar, 3> image;

        // Read the input image
        readQVImageFromFile(argv[1], image);

        // Write output image
        writeQVImageToFile(argv[2], image);
        return 0;

This simple example loads an image from a file named image.png, and stores that same image in another file named image-copy.png.

Compiling and executing the program

Once the files example.cpp and are created in the same directory, you can compile and run the application.

You can use the qmake-qt4 and the make tools to do so from the Linux command shell:

        # qmake-qt4
        # make

This should create the binary executable example. You can execute the application using a command line like the following:

        # ./example

If you are using the Qt Creator, simply load the file This creates a new project containing the source for the small code example described above. You can then compile and execute the example application.

QVision framework. PARP research group. Copyright © 2007, 2008, 2009, 2010, 2011.