Development/Tutorials/Saving and loading (ko): Difference between revisions

    From KDE TechBase
    No edit summary
    Line 259: Line 259:
    ====saveFileAs(QString)====
    ====saveFileAs(QString)====


    Now we get onto our first file handling code. We're going to implement a function which will save the contents of the text area to the file name given as a parameter. KDE provides a class for safely saving a file called {{class|KSaveFile}} which is derived from Qt's {{qt|QFile}}.
    이제 첫번째 파일을 다루는 코드를 살펴보자. 우리는 파라미터로 주어진 파일이름으로 텍스트 공간의 내용을 저장할 함수를 구현할 것이다.
    KDE는 Qt의 {{qt|QFile}}에서 상속되고, 파일을 안전하기 위해 저장하기 위한 {{class|KSaveFile}}라는 클래스를 제공한다.
    :''Now we get onto our first file handling code. We're going to implement a function which will save the contents of the text area to the file name given as a parameter. KDE provides a class for safely saving a file called {{class|KSaveFile}} which is derived from Qt's {{qt|QFile}}.''


    The function's prototype is
    이 함수 원형은 아래와 같다.
    :''The function's prototype is''
    <code cppqt>
    <code cppqt>
    void MainWindow::saveFileAs(const QString &outputFileName)
    void MainWindow::saveFileAs(const QString &outputFileName)
    </code>
    </code>


    We then create our <tt>KSaveFile</tt> object and open it with
    :''우리는 <tt>KSaveFile</tt>오브젝트를 생성하고 그것을 연다.''
    :''We then create our <tt>KSaveFile</tt> object and open it with''
    <code cppqt>
    <code cppqt>
    KSaveFile file(outputFileName);
    KSaveFile file(outputFileName);
    Line 272: Line 276:
    </code>
    </code>


    Now that we have our file to write to, we need to format the text in the text area to a format which can be written to file. For this, we create a {{qt|QByteArray}} and fill it with the plain text version of whatever is in the text area:
    이제 우리는 작성한 파일을 가지고 있으며, 파일을 쓰여질 수 있는 형식으로 text area의 텍스트롤 포맷을 지정해야할 필요가 있다. 이것을 위해, 우리는 {{qt|QByteArray}}을 생성하며, text area안의 어떠한 텍스트 버전이든지 채운다.:
    :''Now that we have our file to write to, we need to format the text in the text area to a format which can be written to file. For this, we create a {{qt|QByteArray}} and fill it with the plain text version of whatever is in the text area:''
    <code cppqt>
    <code cppqt>
    QByteArray outputByteArray;
    QByteArray outputByteArray;
    outputByteArray.append(textArea->toPlainText());
    outputByteArray.append(textArea->toPlainText());
    </code>
    </code>
    Now that we have our <tt>QByteArray</tt>, we use it to write to the file with <tt>KSaveFile::write()</tt>. If we were using a normal <tt>QFile</tt>, this would make the changes immediately. However, if a problem occurred partway through writing, the file would become corrupted. For this reason, <tt>KSaveFile</tt> works by first writing to a temporary file and then, when you call <tt>KSaveFile::finalize()</tt> the changes are made to the actual file.
     
    이제 <tt>QByteArray</tt>롤  가지고 있으며, <tt>KSaveFile::write()</tt>로 파일을 작성기 위해 이것을 사용한다. 만약 일반적인 <tt>QFile</tt>을 사용하였다면, 이것은 즉시 변경될 것이다. 그러나 만약 작성도중 부분적으로 문제가 발생한다면, 파일은 오류를 일으키게 된다. 이러한 이유로 <tt>KSaveFile</tt>은 임시적인 파일을 첫번째로 작성하여 동작하고, <tt>KSaveFile::finalize()</tt>을 호출할 때, 변화된 것이 실제적으로 저장된다.
    :''Now that we have our <tt>QByteArray</tt>, we use it to write to the file with <tt>KSaveFile::write()</tt>. If we were using a normal <tt>QFile</tt>, this would make the changes immediately. However, if a problem occurred partway through writing, the file would become corrupted. For this reason, <tt>KSaveFile</tt> works by first writing to a temporary file and then, when you call <tt>KSaveFile::finalize()</tt> the changes are made to the actual file.''
     
    <code cppqt>
    <code cppqt>
    file.write(outputByteArray);
    file.write(outputByteArray);
    Line 283: Line 291:
    file.close();
    file.close();
    </code>
    </code>
    Finally, we set <tt>MainWindows</tt>'s <tt>fileName</tt> member to point to the file name we just saved to.
     
    마지막으로 우리는 <tt>MainWindows</tt>의 <tt>fileName</tt> 멤버를 우리가 저장한 파일이름을 지정하도록 설정한다.
    :''Finally, we set <tt>MainWindows</tt>'s <tt>fileName</tt> member to point to the file name we just saved to.''
    <code cppqt>
    <code cppqt>
    fileName = outputFileName;
    fileName = outputFileName;
    Line 289: Line 299:


    ====saveFileAs()====
    ====saveFileAs()====
     
    이 함수가 <tt>saveAs</tt> 슬롯이 연결된 함수이다.이것은 일반적으로 간단히 <tt>saveFileAs(QString)</tt> 함수라고 부르며, {{class|KFileDialog}}::[http://api.kde.org/4.0-api/kdelibs-apidocs/kio/html/classKFileDialog.html#8891356c249c5911e1ab15cc2739a89b getSaveFileName()]</tt>에 의해 리턴되는 파일 이름을 얻는다.
    This is the function that the <tt>saveAs</tt> slot is connected to. It simply calls the generic <tt>saveFileAs(QString)</tt> function and passes the file name returned by <tt>{{class|KFileDialog}}::[http://api.kde.org/4.0-api/kdelibs-apidocs/kio/html/classKFileDialog.html#8891356c249c5911e1ab15cc2739a89b getSaveFileName()]</tt>.
    :''This is the function that the <tt>saveAs</tt> slot is connected to. It simply calls the generic <tt>saveFileAs(QString)</tt> function and passes the file name returned by <tt>{{class|KFileDialog}}::[http://api.kde.org/4.0-api/kdelibs-apidocs/kio/html/classKFileDialog.html#8891356c249c5911e1ab15cc2739a89b getSaveFileName()]</tt>.''


    <code cppqt>
    <code cppqt>
    Line 299: Line 309:
    </code>
    </code>


    This our first actual use of the KIO library. {{class|KFileDialog}} provides a number of static functions for displaying the common file dialog that is used by all KDE applications. Calling <tt>KFileDialog::getSaveFileName()</tt> will display a dialog where the user can select the name of the file to save to or choose a new name. The function returns the full file name, which we then pass to <tt>saveFileAs(QString)</tt>.
    이것은 KIO 라이브러리의 첫번째 실질적인 사용이다. {{class|KFileDialog}}은 모든 KDE 어플리케이션에서 사용되는 공통 파일 다이얼로그를 보여주기 위한 많은 static 함수를 제공한다. <tt>KFileDialog::getSaveFileName()</tt>를 호출하는 것은 유저가 저장할 파일의 이름은 선택하거나, 새로운 이름을 고르를 수 있는 다이얼로그를 디스플레이할 것이다. 이 함수는 <tt>saveFileAs(QString)</tt>에 넘기는 전체 파일 이름을 리턴한다.
    :''This our first actual use of the KIO library. {{class|KFileDialog}} provides a number of static functions for displaying the common file dialog that is used by all KDE applications. Calling <tt>KFileDialog::getSaveFileName()</tt> will display a dialog where the user can select the name of the file to save to or choose a new name. The function returns the full file name, which we then pass to <tt>saveFileAs(QString)</tt>.''


    ====saveFile()====
    ====saveFile()====
    Line 317: Line 328:
    </code>
    </code>


    There's nothing exciting or new in this function, just the logic to decide whether or not to show the save dialog. If <tt>fileName</tt> is not empty, then the file is saved to <tt>fileName</tt>. But if it is, then the dialog is shown to allow the user to select a file name.
    이 함수 안에 흥미롭거나 새로운 것은 없다. 단지 다이얼로그를 보일지 말지를 결정하는 로직일 뿐이다. 만약 <tt>fileName</tt>가 비어 있지 않다면, 파일은 <tt>fileName</tt>으로 저장된다. 그러나 만약 비어있다면, 유저가 파일 이름을 선택하기 위한 다이얼로그를 보여준다.
    : ''There's nothing exciting or new in this function, just the logic to decide whether or not to show the save dialog. If <tt>fileName</tt> is not empty, then the file is saved to <tt>fileName</tt>. But if it is, then the dialog is shown to allow the user to select a file name.''


    ===파일 로드하기===
    ===파일 로드하기===

    Revision as of 14:02, 4 January 2008


    Development/Tutorials/Saving_and_loading


    파일 로드하고 저장하기
    Tutorial Series   Beginner Tutorial
    Previous   Tutorial 3 - KActions
    What's Next   Tutorial 5 - KCmdLineArgs 사용하기
    Further Reading   KIO::NetAccess QFile

    개요

    이제 기본적인 텍스트 에디터 인터페이스를 가지게 되었다. 이제는 이것을 좀 더 유용하게 만들 시간이다. 가장 기본적으로 텍스트 에디터는 디스트에서 파일을 로드하고, 당식이 생성했거나 수정한 파일에 저장하거나 파일을 새롭게 생성하도록 할 필요가 있다.

    Now that we have a basic text editor interface, it's time to make it do something useful. At the most basic, a text editor needs to be able to load files from disc, save files that you've created/edited and create new files.

    KDE는 개발자가 좀 더 나은 삶을 위하여 파일을 다루기 위한 많은 클래스를 제공한다. KIO 라이브러리는 표준 다이얼로그와 같은 투명한 네트워크를 통해 파일을 쉽게 접근할 수 있도록 해준다.

    KDE provides a number of classes for working with files which make life a lot easier for developers. The KIO library allows you to easily access files through network-transparent protocols as well as providing standard file dialogs.

    코드

    main.cpp

    1. include <KApplication>
    2. include <KAboutData>
    3. include <KCmdLineArgs>
    1. include "mainwindow.h"

    int main (int argc, char *argv[]) {

     KAboutData aboutData( "tutorial4", "tutorial4",
         ki18n("Tutorial 4"), "1.0",
         ki18n("A simple text area which can load and save."),
         KAboutData::License_GPL,
         ki18n("Copyright (c) 2007 Developer") );
     KCmdLineArgs::init( argc, argv, &aboutData );
     KApplication app;
    
     MainWindow* window = new MainWindow();
     window->show();
     return app.exec();
    

    } main.cpp는 tutrial 3를 tutrial4로 변경한 것을 제외하고는 튜트리얼3에서 변경된 점이 없다.

    main.cpp hasn't changed from tutorial 3 except to change any reference to tutorial 3 to tutorial 4.

    mainwindow.h

    1. ifndef MAINWINDOW_H
    2. define MAINWINDOW_H
    1. include <KXmlGuiWindow>
    2. include <KTextEdit>

    class MainWindow : public KXmlGuiWindow {

     Q_OBJECT //new from tutorial3
     
     public:
       MainWindow(QWidget *parent=0);
     
     private:
       KTextEdit* textArea;
       void setupActions();
       QString fileName; //new
    
     private slots: //new
       void newFile(); //new
       void openFile(); //new
       void saveFile(); //new
       void saveFileAs(); //new
       void saveFileAs(const QString &outputFileName); //new
    

    };

    1. endif

    파일을 로드하고, 저장하는 기능을 추가하려면, 그러한 일을 하는 함수를 만들어야 한다. Qt의 시그널/슬롯 메커니즘을 통해 함수가 호출되기 위해, 19번째 줄에서 수행할 슬롯으로 이러한 함수들을 선언해야 한다. 이 헤더 파일에 있는 슬롯을 사용하는 중이라면, Q_OBJECT 매크로를 추가해야 한다.

    Since we want to add the ability to load and save files, we must add the functions which will do the work. Since the functions will be called through Qt's signal/slot mechanism we must specify that these functions are slots as we do on line 19. Since we are using slots in this header file, we must also add the Q_OBJECT macro.

    또한 우리는 현재 열린 파일의 파일 이름의 흔적을 유지하기를 원하므로, QString fileName을 선언하였다.

    We also want to keep track of the filename of the currently opened file so we declare a QString fileName.

    mainwindow.cpp

    1. include "mainwindow.h"
    1. include <KApplication>
    2. include <KAction>
    3. include <KLocale>
    4. include <KActionCollection>
    5. include <KStandardAction>
    6. include <KFileDialog> //new
    7. include <KMessageBox> //new
    8. include <KIO/NetAccess> //new
    9. include <KSaveFile> //new
    10. include <QTextStream> //new

    MainWindow::MainWindow(QWidget *parent)

       : KXmlGuiWindow(parent),
         fileName(QString()) //new
    

    {

     textArea = new KTextEdit;
     setCentralWidget(textArea);
    
     setupActions();
    

    }

    void MainWindow::setupActions() {

     KAction* clearAction = new KAction(this);
     clearAction->setText(i18n("Clear"));
     clearAction->setIcon(KIcon("document-new"));
     clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
     actionCollection()->addAction("clear", clearAction);
     connect(clearAction, SIGNAL(triggered(bool)),
             textArea, SLOT(clear()));
    
     KStandardAction::quit(kapp, SLOT(quit()),
                           actionCollection());
    
     KStandardAction::open(this, SLOT(openFile()),
                           actionCollection()); //new
    
     KStandardAction::save(this, SLOT(saveFile()),
                           actionCollection()); //new
    
     KStandardAction::saveAs(this, SLOT(saveFileAs()),
                           actionCollection()); //new
    
     KStandardAction::openNew(this, SLOT(newFile()),
                           actionCollection()); //new
    
     setupGUI();
    

    }

    //New from here on

    void MainWindow::newFile() {

     fileName.clear();
     textArea->clear();
    

    }

    void MainWindow::saveFileAs(const QString &outputFileName) {

     KSaveFile file(outputFileName);
     file.open();
     
     QByteArray outputByteArray;
     outputByteArray.append(textArea->toPlainText());
     file.write(outputByteArray);
     file.finalize();
     file.close();
     
     fileName = outputFileName;
    

    }

    void MainWindow::saveFileAs() {

     saveFileAs(KFileDialog::getSaveFileName());
    

    }

    void MainWindow::saveFile() {

     if(!fileName.isEmpty())
     {
       saveFileAs(fileName);
     }
     else
     {
       saveFileAs();
     }
    

    }

    void MainWindow::openFile() {

     QString fileNameFromDialog = KFileDialog::getOpenFileName();
    
     QString tmpFile;
     if(KIO::NetAccess::download(fileNameFromDialog, tmpFile, 
            this))
     {
       QFile file(tmpFile);
       file.open(QIODevice::ReadOnly);
       textArea->setPlainText(QTextStream(&file).readAll());
       fileName = fileNameFromDialog;
    
       KIO::NetAccess::removeTempFile(tmpFile);
     }
     else
     {
       KMessageBox::error(this, 
           KIO::NetAccess::lastErrorString());
     }
    

    }

    tutorial4ui.rc

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> <gui name="tutorial4" version="1">

     <ToolBar name="mainToolBar" >
       <text>Main Toolbar</text>
       <Action name="clear" />
     </ToolBar>
     <MenuBar>
       <Menu name="file" >
         <Action name="clear" />
       </Menu>
     </MenuBar>
    

    </gui>

    name이 'tutorial4'로 바뀐 것을 제외하고 tutrial 3의 tutorial3ui.rc과 동일하다. 우리는 KStandardAction에 대한 어떤 정보도 넣을 필요가 없다. 이 액션의 배치들은 KDE에 의해서 자동적으로 다루어지기 때문이다.

    This is identical to tutorial3ui.rc from tutorial 3 except the name has changed to 'tutorial4'. We do not need to add any information about any of the KStandardActions since the placement of those actions is handled automatically by KDE.

    설명

    자, 이제 로드하거나 저장하기를 수행할 코드를 구현한다. 이것은 mainwindow.cpp에서 모든 것이 일어날 것이다.

    Okay, now to implement the code that will do the loading and saving. This will all be happening in mainwindow.cpp

    우리가 할 첫번째 일은

    The first thing we do is add

    fileName(QString()) 위의 코드를 16번째 줄인 MainWindow 생성자 리스트에 추가하는 것이다. 이것은 시작할 때 fileName이 비어 있도록 해준다.

    to the MainWindow constructor list on line 16. This makes sure that fileName is empty right from the beginning.

    액션 추가하기

    우리가 해야할 첫번째 일은 유저가 어플리케이션에서 로드하고 저장할수 있도록 하기 위한 외부 인터패이스를 제공하는 것이다. 튜트리얼 3에서 quit와 같이 우리는 KStandardActions을 사용할 것이다. 37번째 줄에서 47번째 줄에서, quit 액션과 같은 방식으로 액션을 추가하였다. 각각을 위해 이 액션들을 헤더파일에서 우리가 선언했던 적당한 슬롯에 연결한다.

    The first thing we are going to do is provide the outward interface for the user so they can tell the application to load and save. Like with the quit action in tutorial 3, we will use KStandardActions. On lines 37 to 47 we add the actions in the same way as for the quit action. For each one, we connect it to the appropriate slot that we declared in the header file.

    새 문서 생성하기

    The first function we create is the newFile() function.

    우리가 만든 첫번째 함수는 newFile() 함수이다.

    void MainWindow::newFile() {

     fileName.clear();
     textArea->clear();
    

    } fileName.clear()는 디스크에 이 문서가 아직 존재하재하지 않는다는 사실을 반영하기 위해 fileName QString을 비우도록 설정한다. textArea->clear()은 튜트리얼 3에서 우리가 clear KAction에 연결한 함수와 같은 함수를 사용하여 중앙의 텍스트 공간을 클리어한다.

    fileName.clear() sets the fileName QString to be empty to reflect the fact that this document does not yet have a presence on disc. textArea->clear() then clears the central text area using the same function that we connected the clear KAction to in tutorial 3.

    파일 저장하기

    saveFileAs(QString)

    이제 첫번째 파일을 다루는 코드를 살펴보자. 우리는 파라미터로 주어진 파일이름으로 텍스트 공간의 내용을 저장할 함수를 구현할 것이다. KDE는 Qt의 QFile에서 상속되고, 파일을 안전하기 위해 저장하기 위한 KSaveFile라는 클래스를 제공한다.

    Now we get onto our first file handling code. We're going to implement a function which will save the contents of the text area to the file name given as a parameter. KDE provides a class for safely saving a file called KSaveFile which is derived from Qt's QFile.

    이 함수 원형은 아래와 같다.

    The function's prototype is

    void MainWindow::saveFileAs(const QString &outputFileName)

    우리는 KSaveFile오브젝트를 생성하고 그것을 연다.
    We then create our KSaveFile object and open it with

    KSaveFile file(outputFileName); file.open();

    이제 우리는 작성한 파일을 가지고 있으며, 파일을 쓰여질 수 있는 형식으로 text area의 텍스트롤 포맷을 지정해야할 필요가 있다. 이것을 위해, 우리는 QByteArray을 생성하며, text area안의 어떠한 텍스트 버전이든지 채운다.:

    Now that we have our file to write to, we need to format the text in the text area to a format which can be written to file. For this, we create a QByteArray and fill it with the plain text version of whatever is in the text area:

    QByteArray outputByteArray; outputByteArray.append(textArea->toPlainText());

    이제 QByteArray롤 가지고 있으며, KSaveFile::write()로 파일을 작성기 위해 이것을 사용한다. 만약 일반적인 QFile을 사용하였다면, 이것은 즉시 변경될 것이다. 그러나 만약 작성도중 부분적으로 문제가 발생한다면, 파일은 오류를 일으키게 된다. 이러한 이유로 KSaveFile은 임시적인 파일을 첫번째로 작성하여 동작하고, KSaveFile::finalize()을 호출할 때, 변화된 것이 실제적으로 저장된다.

    Now that we have our QByteArray, we use it to write to the file with KSaveFile::write(). If we were using a normal QFile, this would make the changes immediately. However, if a problem occurred partway through writing, the file would become corrupted. For this reason, KSaveFile works by first writing to a temporary file and then, when you call KSaveFile::finalize() the changes are made to the actual file.

    file.write(outputByteArray); file.finalize(); file.close();

    마지막으로 우리는 MainWindowsfileName 멤버를 우리가 저장한 파일이름을 지정하도록 설정한다.

    Finally, we set MainWindows's fileName member to point to the file name we just saved to.

    fileName = outputFileName;

    saveFileAs()

    이 함수가 saveAs 슬롯이 연결된 함수이다.이것은 일반적으로 간단히 saveFileAs(QString) 함수라고 부르며, KFileDialog::getSaveFileName()에 의해 리턴되는 파일 이름을 얻는다.

    This is the function that the saveAs slot is connected to. It simply calls the generic saveFileAs(QString) function and passes the file name returned by KFileDialog::getSaveFileName().

    void MainWindow::saveFileAs() {

     saveFileAs(KFileDialog::getSaveFileName());
    

    }

    이것은 KIO 라이브러리의 첫번째 실질적인 사용이다. KFileDialog은 모든 KDE 어플리케이션에서 사용되는 공통 파일 다이얼로그를 보여주기 위한 많은 static 함수를 제공한다. KFileDialog::getSaveFileName()를 호출하는 것은 유저가 저장할 파일의 이름은 선택하거나, 새로운 이름을 고르를 수 있는 다이얼로그를 디스플레이할 것이다. 이 함수는 saveFileAs(QString)에 넘기는 전체 파일 이름을 리턴한다.

    This our first actual use of the KIO library. KFileDialog provides a number of static functions for displaying the common file dialog that is used by all KDE applications. Calling KFileDialog::getSaveFileName() will display a dialog where the user can select the name of the file to save to or choose a new name. The function returns the full file name, which we then pass to saveFileAs(QString).

    saveFile()

    void MainWindow::saveFile() {

     if(!fileName.isEmpty())
     {
       saveFileAs(fileName);
     }
     else
     {
       saveFileAs();
     }
    

    }

    이 함수 안에 흥미롭거나 새로운 것은 없다. 단지 다이얼로그를 보일지 말지를 결정하는 로직일 뿐이다. 만약 fileName가 비어 있지 않다면, 파일은 fileName으로 저장된다. 그러나 만약 비어있다면, 유저가 파일 이름을 선택하기 위한 다이얼로그를 보여준다.

    There's nothing exciting or new in this function, just the logic to decide whether or not to show the save dialog. If fileName is not empty, then the file is saved to fileName. But if it is, then the dialog is shown to allow the user to select a file name.

    파일 로드하기

    Finally, we get round to being able to load a file from disc. The code for this is all contained in MainWindow::openFile().

    First we must ask the user for the name of the file they wish to open. We do this using another one of the KFileDialog functions, this time getOpenFileName(): QString fileNameFromDialog = KFileDialog::getOpenFileName();

    Then we use the KIO library to retrieve our file. This allows us to open the file with QFile even if it's stored in a remote location like an FTP site. We make the following call to NetAccess's download() function KIO::NetAccess::download(fileNameFromDialog, tmpFile, this) The first argument is the name of the file you wish to download. The second is a QString which, after the download is complete, will contain the location of the temporary copy of the file. It is this tmpFile we will work with from now on.

    The function returns true or false depending on whether the transfer was successful. If it failed, we display a message box giving the error: KMessageBox::error(this, KIO::NetAccess::lastErrorString());

    Otherwise, we continue with opening the file.

    We create a QFile by passing the temporary file created by NetAccess::download() to its constructor and then open it in read-only mode QFile file(tmpFile); file.open(QIODevice::ReadOnly);

    In order to display the contents of the file, we must use a QTextStream. We create one by passing the contents of our file to its constructor and then call QFile's readAll() function to get the text from the file. This is then passed to the setPlainText() function of our text area.

    textArea->setPlainText(QTextStream(&file).readAll());

    We then store the path of the file we just opened: fileName = fileNameFromDialog; and finally, we remove the temporary file that was created by NetAccess::download(): KIO::NetAccess::removeTempFile(tmpFile);

    Make, Install And Run

    CMakeLists.txt

    project(tutorial4)

    find_package(KDE4 REQUIRED) include_directories(${KDE4_INCLUDES})

    set(tutorial4_SRCS

     main.cpp
     mainwindow.cpp
    

    )

    kde4_add_executable(tutorial4 ${tutorial4_SRCS})

    target_link_libraries(tutorial4 ${KDE4_KDEUI_LIBS}

                                   ${KDE4_KIO_LIBS})
    
    

    install(TARGETS tutorial4 DESTINATION ${BIN_INSTALL_DIR}) install(FILES tutorial4ui.rc

           DESTINATION ${DATA_INSTALL_DIR}/tutorial4)
    

    Since we are now using the KIO library, we must tell CMake to link against it. We do this by passing ${KDE4_KIO_LIBS} to the target_link_libraries() function.

    With this file, the tutorial can built and run in the same way as tutorial 3. For more information, see tutorial 3.

    mkdir build && cd build
    cmake .. -DCMAKE_INSTALL_PREFIX=$HOME
    make install
    $HOME/bin/tutorial4
    

    나아가기

    이제 우리는 KCmdLineArgs 튜트리얼을 진행할 수 있다.

    Now you can move on to the KCmdLineArgs tutorial.