Image Viewer Tutorial: Part 1
|
List Screen | Image Screen | Info Screen | Rename Dialog |
---|---|---|---|
For the parts 1-7 the source code can be found in examples/imageviewer
First the project file has to be created (qbuild.pro) for the Qt Extended build system.
File: qbuild.pro
TEMPLATE=app CONFIG+=qtopia TARGET=iviewer CONFIG+=quicklaunch HEADERS += iviewer.h SOURCES += main.cpp iviewer.cpp
Here a Qt Extended application is declared (iviewer). The start code will be in main and the application in iviewer{.h,.cpp}.
File: main.cpp
#include "iviewer.h" #include <qtopiaapplication.h> QTOPIA_ADD_APPLICATION(QTOPIA_TARGET, IViewer) QTOPIA_MAIN
"IViewer" is the class name and "iviewer" is the executable name. The syntax is described here.
Classes: QtopiaApplication
File: iviewer.h
#ifndef IVIEWER_H #define IVIEWER_H #include <QStackedWidget> #include <QWidget> class IViewer : public QStackedWidget { Q_OBJECT public: IViewer(QWidget *parent=0, Qt::WFlags f=0); }; #endif
Classes: QStackedWidget, QWidget
The IViewer should be a QStackedWidget derived class. The widget stack will be used later to manage our screens. The constructor needs to have the QWidget and Qt::WindowFlags as parameters, due to the QTOPIA macros in main.cpp.
File: iviewer.cpp
#include "iviewer.h"
IViewer::IViewer(QWidget *parent, Qt::WFlags /*f*/)
: QStackedWidget(parent)
{
_listScreen = 0;
_imageScreen = 0;
setCurrentWidget(listScreen());
setWindowTitle("Image Viewer");
}
Namespace: Qt
It is now time for the first run. qbuild must be called. When the QVFB emulator is running, the application can be started with ./iviewer. This should display an empty application in the emulator. Great!
The list screen will be derived from the QListWidget for convenience.
File: listscreen.h
#ifndef LISTSCREEN_H #define LISTSCREEN_H #include <QListWidget> class IViewer; class QContentSet; class QContentSetModel; class QAction; class QKeyEvent; class ImageScreen; class InfoScreen; class ListScreen : public QListWidget { Q_OBJECT public: ListScreen(IViewer *viewer); private: IViewer *_viewer; }; #endif
Classes: QListWidget
As parent, the iviewer is passed and the pointer is stored in _iviewer. The forward declaration (class IViewer) is used to avoid dependency with the created header files. Dependencies to Qt/Qt Extended header files do not have to be handled.
File: listscreen.cpp
#include "listscreen.h" #include "iviewer.h" ListScreen::ListScreen(IViewer *viewer) : QListWidget(viewer), _viewer(viewer) { }
The list widget is constructed and the _viewer is initialized. The project (qbuild.pro) should know about the new class. The following lines must be added to the qbuild.pro file:
File: qbuild.pro
SOURCES += listscreen.cpp HEADERS += listscreen.h
Now, qbuild can be run again. The application should still display an empty screen. To see something useful, the screen in the iviewer has to be created and the list must be populated with some content. This will be the next step.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt qtextended4.4 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com