![]() |
University of Murcia ![]() |
Hello worldAs any other Qt-based application, QVision applications are created inside a Qt project. Qt project files specify the source files and compilation parameters necessary to create any Qt application.The following is the content of an example Qt project file to create a QVision application from a single C++ source file named example.cpp:
include(/usr/local/QVision/qvproject.pri) TARGET = example SOURCES = example.cpp Any QVision application's .pro file must include the file qvproject.pri. This file is a qmake project file, that contains the setup instructions for compiling applications with the QVision. It is included either in the sources of the QVision, or in the QVision installation directory. The line TARGET = example assigns the name of the application's executable to example. TARGET is a reserved variable name inside the Qt project files, 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 example.pro, and create the source file example.cpp which will contain the source code of our hello-world application. Source code for the 'example.cpp' fileWe can insert the following code in the example.cpp file formerly described:
#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); } This simple example only loads an image from a file, and stores that image in another file. Compiling and executing the programOnce the files example.cpp and example.pro are created in the same directory, you can compile the application using the qmake-qt4 and the make tools:
# qmake-qt4 # make This should create the binary executable example. You can execute the application using a command line like the following:
# ./example lena.png lena-copy.png
Assuming that an image file named lena.png exists, a copy of the image contained in it will be created in the file lena-copy.jpg. |