KDE TechBase
  • Page
  • Discussion
  • Edit
  • History
KDE TechBase is a Wiki - You can help! Please contribute! Questions?
Please ask development related questions in the KDE Community Forum.

Development/Tutorials/Using KXmlGuiWindow (pt BR)

< Development | Tutorials

Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenščina | српски | Українська | 简体中文 | 繁體中文

Como usar o KXmlGuiWindow
Série de Tutoriais   Tutorial para iniciantes
Pré-requisitos   Tutorial 1 - Alô Mundo
Qual é o próximo   Tutorial 3 - KActions e XMLGUI
Leitura adicional   KXmlGuiWindow

Contents

  • 1 Resumo
  • 2 KXmlGuiWindow
    • 2.1 mainwindow.h
    • 2.2 mainwindow.cpp
  • 3 De volta ao main.cpp
    • 3.1 main.cpp
  • 4 CMake
    • 4.1 CMakeLists.txt
    • 4.2 Compile isto
  • 5 Siga em frente

[edit] Resumo

Este tutorial dá continuidade ao First Program Tutorial e introduzirá a classe KXmlGuiWindow.

No tutorial anterior, o programa criava uma caixa de diálogo pop up, mas nós agora iremos andar alguns passos em direção ao funcionamento de uma aplicação.

[edit] KXmlGuiWindow

KXmlGuiWindow fornece a visão de uma janela principal inteira com barra de menus, barra de ferramentas, uma barra de status e uma área no centro para um widget grande. Muitas aplicações KDE derivam desta classe já que ela fornece um jeito fácil de definir o layout do menu e barra de ferramentas através de arquivos XML (esta tecnologia é chamada de XMLGUI). Por enquanto não usaremos o XMLGUI neste tutorial, mas nós o usaremos no próximo.

In order to have a useful KXmlGuiWindow, we must subclass it. So we create two files, a mainwindow.cpp and a mainwindow.h which will contain our code.

[edit] mainwindow.h

  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <KXmlGuiWindow>
  5. #include <KTextEdit>
  6.  
  7. class MainWindow : public KXmlGuiWindow
  8. {
  9. public:
  10. MainWindow(QWidget *parent=0);
  11.  
  12. private:
  13. KTextEdit* textArea;
  14. };
  15.  
  16. #endif

First we Subclass KXmlGuiWindow on line 7 with class MainWindow : public KXmlGuiWindow.

Então nós declaramos o construtor com MainWindow(QWidget *parent=0);.

And finally we declare a pointer to the object that will make up the bulk of our program. KTextEdit is a generic richtext editor with some KDE niceties like cursor auto-hiding.

[edit] mainwindow.cpp

  1. #include "mainwindow.h"
  2.  
  3. MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent)
  4. {
  5. textArea = new KTextEdit();
  6. setCentralWidget(textArea);
  7. setupGUI();
  8. }

Primeiro, é claro, na linha 1 nós temos que incluir o arquivo de cabeçalho contendo a declaração da classe.

Na linha 5, nós iniciamos nosso editor de texto com um objeto. Então na linha 6 nós usamos a função setCentralWidget() do KXmlGuiWindow a qual chama o KXmlGuiWindow que deverá aparecer na parte central da janela.

Finalmente, KXmlGuiWindow::setupGUI() é chamado, a qual faz várias coisas por-trás-dos-bastidores e cria a barra de menu padrão (Configurações, Ajuda).

[edit] De volta ao main.cpp

No intuito de executar atualmente esta janela, nós adicionamos umas poucas linhas no main.cpp

[edit] main.cpp

  1. #include <KApplication>
  2. #include <KAboutData>
  3. #include <KCmdLineArgs>
  4.  
  5. #include "mainwindow.h"
  6.  
  7. int main (int argc, char *argv[])
  8. {
  9. KAboutData aboutData( "tutorial2", 0,
  10. ki18n("Tutorial 2"), "1.0",
  11. ki18n("A simple text area"),
  12. KAboutData::License_GPL,
  13. ki18n("Copyright (c) 2007 Developer") );
  14. KCmdLineArgs::init( argc, argv, &aboutData );
  15.  
  16. KApplication app;
  17.  
  18. MainWindow* window = new MainWindow();
  19. window->show();
  20.  
  21. return app.exec();
  22. }

As únicas linhas novas aqui (comparadas com o Tutorial 1) são 5, 18 e 19. Na linha 18, nós criamos o nosso objeto MainWindow e então, na linha 19, nós a exibimos.

[edit] CMake

The best way to build the program is to use CMake. All that's changed since tutorial 1 is that mainwindow.cpp has been added to the sources list and any tutorial1 has become tutorial2.

[edit] CMakeLists.txt

  1. project (tutorial2)
  2.  
  3. find_package(KDE4 REQUIRED)
  4. include_directories(${KDE4_INCLUDES})
  5.  
  6. set(tutorial2_SRCS
  7. main.cpp
  8. mainwindow.cpp
  9. )
  10.  
  11. kde4_add_executable(tutorial2 ${tutorial2_SRCS})
  12. target_link_libraries(tutorial2 ${KDE4_KDEUI_LIBS})

[edit] Compile isto

Para compilar, crias as ligações e rodar, use:

mkdir build && cd build
cmake ..
make
./tutorial2

[edit] Siga em frente

Agora você pode ir ao tutorial usando KActions.

Retrieved from "http://techbase.kde.org/Development/Tutorials/Using_KXmlGuiWindow_(pt_BR)"
Categories: Tutorial | C++

Navigation

  • Home
  • Help
  • Recent changes

Sections

  • Getting started
  • Development
  • Schedules
  • Policies
  • Contribute
  • Projects

Toolbox

  • What links here
  • Related changes
  • Special pages
  • Printable version
  • Permanent link

Personal tools

  • 38.107.191.95
  • Talk for this IP
  • Log in / create account
  • Login with OpenID
Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal