1. Hello. desktop file
Http://blog.chinaunix.net/uid-26729065-id-3212772.html
[Desktop entry]
Comment = An example Program <--- description
Exec = Hello <--- executable program
Icon = games <---- icon
Type = application <--- type
Name = hello2440 <---- name under the icon
2. Hello. Pro File
Config + = qtopiaapp
Config-= buildquicklaunch
Destdir = $ (PWD)
Includepath + =./usr/local/include/opencv
Libs + =/usr/local/lib/libcv. so.4 \
/Usr/local/lib/libcvaux. so.4 \
/Usr/local/lib/libcxcore. so.4 \
/Usr/local/lib/libhighgui. so.4 \
/Usr/local/lib/libml. so.4 \
-Lpthread
Headers = Hello. h // header file
Sources = Hello. cpp // source file
Sources + = Main. cpp
Desktop. Files = Hello. Desktop // desktop file
Desktop. Path =/apps/Applications
Install+ = Desktop
Interfaces = hello_base.ui
Target = Hello // generated Executable File
3. Main. cpp
# Include "Hello. H"
# Include <qtopia/qpeapplication. h>
Qtopia_add_application ("hello", helloform) // Class Name
Qtopia_main
4. Hello. h
# Ifndef helloform_h
# Define helloform_h
# Include "hello_base.h"
# Include <pthread. h>
# Include <qtimer. h>
# Include <qlabel. h>
# Include <qstring. h>
# Include <qtimer. h>
# Include <cv. h>
# Include <cxcore. h>
# Include # Include <qpixmap. h>
# Include <qimage. h>
# Include <qdir. h>
// Class qdir;
Class helloform: Public
Hellobaseform (designer-designed class name)
{
Q_OBJECT
Public:
HelloForm (QWidget * parent = 0, const char * name = 0, WFlags fl = 0 );
Virtual ~ HelloForm ();
Protected:
Virtual void SayHello ();
QTimer * timer;
Int I, j, t1, t2, t3;
QDir dir;
Private slots:
Void showThread ();
Void test1 ();
Void test2 ();
Protected:
Void timerEvent (QTimerEvent * e );
};
# Endif // HELLOFORM_H
A slot is a common C ++ member function that can be called normally. Its unique characteristic is that many signals can be associated with it. This slot is called when the signal associated with it is sent. Slot can have parameters, but slot parameters cannot have default values.
Since the slot is a common member function, like other functions, they also have access permissions. The access permission of the slot determines who can be associated with it. Like common C ++ member functions, slots are also divided into three types: public slots, private slots, and protected slots.
- Public slots: The slots declared in this region means that any object can connect the signal to it. This is very useful for component programming. You can create objects that do not know each other and connect their signals to the slot so that information can be correctly transmitted.
- Protected slots: The slots declared in this region means that the current class and its subclass can connect signals to it. This applies to those slots, which are part of the class implementation, but their interface interfaces are external-oriented.
- Private slots: The slots declared in this region means that only the class itself can connect the signal with it. This applies to closely related classes.
The slot can also be declared as a virtual function, which is also very useful.
The slot statement is also carried out in the header file.
5. hello. cpp
# Include "hello. h"
# Include <qlabel. h>
# Include <qpushbutton. h>
# Include <qtextcodec. h>
# Include <qtopia/global. h>
# Include <qtopia/applnk. h>
# Include <qtopia/qpeapplication. h>
# Include <qfile. h>
# Include <qdir. h>
QTextCodec * codec = QTextCodec: codecForName ("UTF-8 ");
HelloForm: HelloForm (QWidget * parent, const char * name, WFlags fl ):
HelloBaseForm (parent, name, fl), dir ("/mnt ")
{
I = j = 0;
Setcaption (codec-> tounicode ("first test program"); // QT Text Encoding
Pushbutton1-> settext (codec-> tounicode ("hello "));
Timer = new qtimer (this );
Timer-> Start (10 );
Connect (timer, signal (timeout (), this, slot (test1 ();/* qtimer class provides timer signals and single-trigger timers. It uses timer events internally to provide more general timers. Qtimer is easy to use
Use: Create a qtimer, use start () to start and connect its timeout () to the appropriate slot. When this time passes, it will launch
Timeout () signal */
T1 = starttimer (100); // Its return value is T1, that is, its timerid is T1
T2 = starttimer (10); // Its return value is T2, that is, its timerid is T2
T3 = starttimer (10000); // Its return value is T3, that is, its timerid is T3
}
Helloform ::~ Helloform ()
{
}
Void helloform: showthread ()
{
Textlabel1-> setnum (I );
Textlabel2-> setnum (j );
}
Void helloform: test1 ()
{
Textlabel1-> setnum (I ++ );
}
Void helloform: Test2 ()
{
}
Void helloform: sayhello ()
{
Dir. setfilter (qdir: files );
Int I, J = dir. Count ()-1;
For (I = 0; I <= J; I ++)
Dir. Remove (dir [I]);
}
Void helloform: timerevent (qtimerevent * E)
{
If (e-> timerid () = T3)
Test2 ();
}