官术网_书友最值得收藏!

The ImageEditor application

In this chapter, we will build an application that can be used to edit images, so we will name it ImageEditor. To edit an image with a GUI application, the first step is opening and viewing the image with that application, which is what we did in the previous chapter. Therefore, I decided to make a copy of the ImageViewer application and rename it ImageEditor, before adding the image editing features to it.

Let's start by copying the sources:

    $ mkdir Chapter-02
$ cp -r Chapter-01/ImageViewer/ Chapter-02/ImageEditor
$ ls Chapter-02
ImageEditor
$ cd Chapter-02/ImageEditor
$ make clean
$ rm -f ImageViewer

With these commands, we copy the ImageViewer directory under the Chapter-01 directory to Chapter-02/ImageEditor. Then, we can enter that directory, run make clean to clean all intermediate files that were generated in the compiling process, and remove the old target executable file using rm -f ImageViewer.

 Now that we have a cleaned project, let's rename some of it:

  • The project directory is named with the new project name ImageEditor in the copying process, so we don't need to do anything here.
  • The Qt project file, ImageViewer.pro, should be renamed to ImageEditor.pro. You can do this in your file manager or in a Terminal.
  • In the ImageEditor.pro file, we should rename the TARGET to ImageEditor by changing the TARGET = ImageViewer line to TARGET = ImageEditor.
  • In the source file, main.cpp, we should change the window title by changing the window.setWindowTitle("ImageViewer"); line to window.setWindowTitle("ImageEditor");.

Now that everything has been renamed, let's compile and run the new ImageEditor application, which has been copied from ImageViewer:

    $ qmake -makefile
$ make
g++ -c -pipe ...
# output truncated
# ...
$ ls
ImageEditor ImageEditor.pro main.cpp main.o mainwindow.cpp mainwindow.h
mainwindow.o Makefile moc_mainwindow.cpp moc_mainwindow.o moc_predefs.h
$ export LD_LIBRARY_PATH=/home/kdr2/programs/opencv/lib/
$ ./ImageEditor

You will see that the window is exactly the same as the window of ImageViewer, except that it has a different window title, ImageEditor. Anyway, we have set our editor application up, even though it has no feature for image editing now. We will add a simple editing feature in the next chapter.

主站蜘蛛池模板: 布尔津县| 铜梁县| 利川市| 高青县| 乌兰县| 铁岭县| 攀枝花市| 姜堰市| 宜君县| 东阳市| 酒泉市| 蒲江县| 隆化县| 莱州市| 永登县| 堆龙德庆县| 平乡县| 禹城市| 德惠市| 岳阳县| 克拉玛依市| 樟树市| 环江| 西乌珠穆沁旗| 石楼县| 八宿县| 新营市| 太仓市| 金湖县| 定结县| 中牟县| 华蓥市| 上饶县| 怀柔区| 通山县| 永寿县| 平舆县| 仁布县| 南投县| 新沂市| 株洲市|