• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KTextEditor

How to use the KTextEditor Interfaces

Overview | Design | Coding Guidelines | Porting to KDE 4 | Using

This HOWTO will explain step by step how to load a KTextEditor component and plug a single View into a KMainWindow.

Tobics:

  • The Header File
  • The Mainwindow Implementation
  • Notes

The Header File

The following class only contains two pointers to a Document and its View.

  #include <kxmlguiwindow.h>

  namespace KTextEditor
  {
    class Document;
    class View;
  }

  class MainWindow : public KXmlGuiWindow
  {
  Q_OBJECT

  public:
    MainWindow();
    ~MainWindow();

  private:
    KTextEditor::View *m_view;
    KTextEditor::Document *m_document;
  };

The Mainwindow Implementation

The following source code queries for a Editor part by using the EditorChooser. If the returned Editor is invalid, we simply quit, otherwise we create a new document and a view and plug it into the mainwindow.

  #include "mainwindow.h"
  #include <ktexteditor/document.h>
  #include <ktexteditor/view.h>
  #include <ktexteditor/editor.h>
  #include <ktexteditor/editorchooser.h>

  #include <kxmlguifactory.h>
  #include <kmessagebox.h>

  MainWindow::MainWindow ()
    : KXmlGuiWindow(),
      m_view(0),
      m_document(0)
  {
    KTextEditor::Editor *editor = KTextEditor::EditorChooser::editor();

    if (!editor) {
      KMessageBox::error(this, i18n("A KDE text-editor component could not be found;\n"
                                    "please check your KDE installation."));
      kapp->exit(1);
    }

    m_document = editor->createDocument(0);
    m_view = m_document->createView(this);

    setCentralWidget(m_view);

    setXMLFile("mainwindowui.rc");
    guiFactory()->addClient(m_view);

    show ();
  }

  MainWindow::~MainWindow()
  {
    if (m_document) {
      guiFactory()->removeClient(m_view);

      // the document deletes its views itself
      delete m_document;
    }
  }

Notes

In order to compile link against the following libraries:

  • ktexteditor
  • kdeui
Author:
Dominik Haumann <dhdev@gmx.de>

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal