On s'attachera à appliquer systématiquement les deux outils que l'on connaît désormais: SVN et Doxygen.
On commence par définir son environnement Svn :
$> cd ~/Project $> mkdir TpQt $> svn add TpQt $> svn ci -m "Creating the TpQt directory"
$> cd ~/Project/TpQt $> mkdir source $> cd ~/Project/TpQt/source $> mkdir include src
#ifndef MYWINDOW_H #define MYWINDOW_H #include <QtGui/QMainWindow> #include <QtGui/QPushButton> /// \file MyWindow.h /// \author IPN teaching <ivana@ipno.in2p3.fr> /// \date November 2008 /// /// \brief First class MyWindow based on Qt class MyWindow : public QMainWindow { // Macro Q_OBJECT necessary to specify the use of Qt internal mechanism // for communication between classes. Q_OBJECT public: /// \brief The main constructor MyWindow( QMainWindow* parent = 0, Qt::WFlags fl = Qt::Window ); /// \brief Destructor of the class virtual ~MyWindow(); private: QPushButton* m_hello; ///< our push button }; #endif // MYWINDOW_H
/// \file MyWindow.cxx /// \author IPN teaching <ivana@ipno.in2p3.fr> /// \date November 2008 /// /// \brief First class MyWindow based on Qt #include "MyWindow.h" /// Method for creating the MyWindow class <br /> /// Our class, which will be be a graphical window display, /// should inherit from the Qt QMainWindow class /// \param parent : Parent widget, parent of the class. In our case, /// this is the main window, so the parent will be "NULL" /// \param flags : The creation flags of the window. Can be used /// to create a non-rediomensionnable window, without an exit button ... etc. ... MyWindow::MyWindow( QMainWindow* parent, Qt::WFlags fl ) : QMainWindow( parent, fl ) { // Create our push button m_hello = new QPushButton( "Hello world!" ); // put the text that you want to see ... // Display our button in a central position setCentralWidget( m_hello ); } /// Destroy object MyWindow and all objects contained inside. /// In particular, the button previously created. MyWindow::~MyWindow() { delete m_hello; }
Puis ajouter la fonction main dans le fichier QtTest.cxx:
/// \file QtTest.cxx /// \author IPN teaching <ivana@ipno.in2p3.fr> /// \date November 2008 /// \brief First HelloWorld in Qt #include <QApplication> #include <QPushButton> #include <MyWindow.h> int main(int argc, char *argv[]) { QApplication app(argc, argv); MyWindow* myWindow = new MyWindow(); myWindow->show(); return app.exec(); }
$> cd ~/Project/TpQt $> qmake -project $> qmake -spec macx-g++
RECURSIVE = YES
$> make $> open TpQt.app $> doxygen
$> svn add source Doxyfile $> svn ci -m "First version" .
Pour cela, il suffit simplement d'ajouter la ligne suivante, juste après la création du bouton, dans MyWindow.cxx:
// Connect the clicked() signal of the graphical button to the QMainWindow // method close() connect( m_hello, SIGNAL(clicked()), this, SLOT(close()) );
$> make $> doxygen $> open TpQt.app $> svn ci -m "Activation of a graphics button" .
Ajouter les includes suivants dans le fichier MyWindow.cxx:
#include <QMenu> #include <QMenuBar>
Puis ajouter le code suivant dans le constructeur de la classe MyWindow :
MyWindow::MyWindow( QMainWindow* parent, Qt::WFlags fl ) : QMainWindow( parent, fl ) { //... // Display button in a central position setCentralWidget(m_hello); // Creation of menuBar QMenuBar* menuBar = new QMenuBar(this); // Creating a menu "File" QMenu* menuFile = new QMenu("File"); // And adding the menu "File" in the menu bar menuBar->addMenu(menuFile); // Now we add our items // Add an item "Open" menuFile->addAction("Open"); // Add a separator menuFile->addSeparator(); // Add an item "Bye" connected to the slot "close" of the mainWindow menuFile->addAction("Bye", this, SLOT(close()) ); // Then set the menu bar to the main window setMenuBar(menuBar); }
Pour cela, nous allons commencer par ajouter une action "Change" à notre menu "File", que l'on va connecter à la fonction change() définie par la suite. À la suite de la création de l'action "Open" ajouter les lignes suivantes :
// Add a new item "Change" that connects to the function change() menuFile->addAction("Change", this, SLOT(change()) );
public slots : void change();
/// This method changes the text button m_hello. /// The documentation for the QPushButton methods is available at: /// <a href="http://doc.trolltech.com/4.0/qpushbutton.html">QPushButton</a><br /> /// The QPushButton is a special type of button. Possible buttons are /// PushButton, CheckButton, RadioButton ... etc. ... They all inherit /// the properties of an abstract button type called QAbstractButton. /// The documentation on QAbstractButton methods is available at: /// <a href="http://doc.trolltech.com/4.0/qabstractbutton.html">QAbstractButton</a><br /> void MyWindow::change() { m_hello->setText("..."); // Complete the line above according to the documentation }