C++ ile QT için signal ve slot kullanmaya örnek bir proje
1 ////////////////////////////////////////////////////// Main.cpp
2 //////////////////////////////////////////////////////
3
4 #include <QtGui>
5 #include "pencere.h"
6
7 int main(int argc, char *argv[])
8 {
9 QApplication app(argc, argv);
10
11 if (!QSystemTrayIcon::isSystemTrayAvailable()) {
12 QMessageBox::critical(0, QObject::tr("Uyari!"),
13 QObject::tr("Bu bilgisayarda herhangi bir "
14 "görev bölmesi bulunamad?."));
15 return 1;
16 }
17
18
19 AnaPencere p;
20
21 p.show();
22 return app.exec();
23 }
24
25 ////////////////////////////////////////////////////// pencere.h
26 //////////////////////////////////////////////////////
27
28 #include <QMainWindow>
29 #include <QSystemTrayIcon>
30 #include "ui_pencere.h"
31
32 class AnaPencere:public QMainWindow, Ui::MainWindow
33 {
34 Q_OBJECT
35 public:
36 QSystemTrayIcon *SistemTepsiSimgesi;
37
38 //kurucu fonksiyon
39 AnaPencere():QMainWindow()
40 {
41 setupUi(this);
42 connect(dugme, SIGNAL(clicked()), this, SLOT(balonac()));
43
44 SistemTepsisineSimgeKoy();
45 }
46
47
48
49 public slots:
50 void balonac()
51 {
52 // bu slot dugmeye basinca calisacak
53 QSystemTrayIcon::MessageIcon ipucusimgesi = QSystemTrayIcon::MessageIcon(1);
54 SistemTepsiSimgesi->showMessage(baslik->text(), ileti->toPlainText(), ipucusimgesi, 5000);
55 }
56
57 void AnaPencere::SistemTepsisineSimgeKoy()
58 {
59 //Buradan simgeye sa? tu? menüsü eklenebilir.
60 SistemTepsiSimgesi = new QSystemTrayIcon(this);
61 SistemTepsiSimgesi->show();
62 SistemTepsiSimgesi->setIcon(QIcon(QString::fromUtf8(":/simgeler/resimler/heart.svg")));
63 }
64
65
66 };
67
68
69 ////////////////////////////////////////////////////// pencere.ui
70 //////////////////////////////////////////////////////
71
72 <ui version="4.0" >
73 <class>MainWindow</class>
74 <widget class="QMainWindow" name="MainWindow" >
75 <property name="geometry" >
76 <rect>
77 <x>0</x>
78 <y>0</y>
79 <width>349</width>
80 <height>265</height>
81 </rect>
82 </property>
83 <property name="windowTitle" >
84 <string>Pencere</string>
85 </property>
86 <property name="windowIcon" >
87 <iconset resource="resim_kaynagi.qrc" >:/simgeler/resimler/bad.svg</iconset>
88 </property>
89 <widget class="QWidget" name="centralwidget" >
90 <widget class="QLabel" name="etiket1" >
91 <property name="geometry" >
92 <rect>
93 <x>10</x>
94 <y>20</y>
95 <width>44</width>
96 <height>18</height>
97 </rect>
98 </property>
99 <property name="text" >
100 <string>Ba?l?k :</string>
101 </property>
102 </widget>
103 <widget class="QLabel" name="etiket2" >
104 <property name="geometry" >
105 <rect>
106 <x>20</x>
107 <y>60</y>
108 <width>31</width>
109 <height>18</height>
110 </rect>
111 </property>
112 <property name="text" >
113 <string>?leti :</string>
114 </property>
115 </widget>
116 <widget class="QLineEdit" name="baslik" >
117 <property name="geometry" >
118 <rect>
119 <x>80</x>
120 <y>20</y>
121 <width>251</width>
122 <height>23</height>
123 </rect>
124 </property>
125 </widget>
126 <widget class="QTextEdit" name="ileti" >
127 <property name="geometry" >
128 <rect>
129 <x>80</x>
130 <y>60</y>
131 <width>251</width>
132 <height>141</height>
133 </rect>
134 </property>
135 </widget>
136 <widget class="QPushButton" name="dugme" >
137 <property name="enabled" >
138 <bool>true</bool>
139 </property>
140 <property name="geometry" >
141 <rect>
142 <x>230</x>
143 <y>220</y>
144 <width>101</width>
145 <height>27</height>
146 </rect>
147 </property>
148 <property name="text" >
149 <string>Göster</string>
150 </property>
151 </widget>
152 </widget>
153 </widget>
154 <resources>
155 <include location="resim_kaynagi.qrc" />
156 </resources>
157 <connections/>
158 </ui>
159
160
161 ////////////////////////////////////////////////////// resim_kaynagi.qrc
162 ////////////////////////////////////////////////////// Bu çok önemli degil, saatin yanina simge koymak için kullanmistim.
163 ////////////////////////////////////////////////////// internetten herhangi bir svg uzantili resim bulup koyun. ben wikipedia 'dan bulmustum.
164
165
166 <RCC>
167 <qresource prefix="/simgeler" >
168 <file>resimler/bad.svg</file>
169 <file>resimler/heart.svg</file>
170 <file>resimler/trash.svg</file>
171 </qresource>
172 </RCC>
Code en C permettant l'accès a une base de donnée MySQL C code wich permit MySQL access
1 /*********************************************************
2 **Attention il est impératif de compiler ce code avec l'option de compilation -lmysqlclient
3 **********************************************************/
4
5 #include <stdio.h>
6 #include <errno.h>
7 #include <stdlib.h>
8 #include <iostream.h>
9 #include <fstream>
10 #include <mysql/mysql.h>
11 #include <sys/types.h>
12 #include <sys/wait.h>
13
14 #define MY_SERVER_HOST "localhost"
15 #define MY_SERVER_PORT 0
16 #define MY_ACCOUNT "root"
17 #define MY_PASS "test"
18 #define MY_DB_NAME "itest"
19 #define MY_TABLE_NAME "test_tbl"
20 #define MY_UX_SOCK NULL
21 #define MY_CLIENT_FLAG 0
22
23 void main()
24 {
25 MYSQL *mysql;
26 MYSQL_RES *res;
27 MYSQL_ROW row;
28 MYSQL_ROW rowchamps;
29 const char *query;
30 string qutmp;
31
32 int t,f,tt,ff;
33
34 mysql=mysql_init(NULL);
35
36 if (!mysql_real_connect(mysql,MY_SERVER_HOST,MY_ACCOUNT,MY_PASS,bd,MY_SERVER_PORT,MY_UX_SOCK,MY_CLIENT_FLAG)) {
37 printf( "Erreur de connexion : %s\n",mysql_error(mysql));
38 }
39 else {
40 qutmp = "SHOW FULL COLUMNS FROM TABLE ";
41 query = qutmp.c_str();
42 t=mysql_real_query(mysql, query, (unsigned int) strlen(query));
43 if((res=mysql_use_result(mysql))) {
44 f=mysql_num_fields(res);
45 while((row=mysql_fetch_row(res))) {
46 for(f=0;f<t;f++){
47 cout<<row[f]<<endl;
48 }
49 }
50 mysql_free_result(res);
51 }
52 }
53 mysql_close(mysql);
54 }
Exemple d'utilisation Accents.clean("mämé") == "mame"
1 class Accents:
2 __reptable = {}
3
4 __corresp = [
5 (u"A", [0x00C0,0x00C1,0x00C2,0x00C3,0x00C4,0x00C5,0x0100,0x0102,0x0104]),
6 (u"AE", [0x00C6]),
7 (u"a", [0x00E0,0x00E1,0x00E2,0x00E3,0x00E4,0x00E5,0x0101,0x0103,0x0105]),
8 (u"ae", [0x00E6]),
9 (u"C", [0x00C7,0x0106,0x0108,0x010A,0x010C]),
10 (u"c", [0x00E7,0x0107,0x0109,0x010B,0x010D]),
11 (u"D", [0x00D0,0x010E,0x0110]),
12 (u"d", [0x00F0,0x010F,0x0111]),
13 (u"E", [0x00C8,0x00C9,0x00CA,0x00CB,0x0112,0x0114,0x0116,0x0118,0x011A]),
14 (u"e", [0x00E8,0x00E9,0x00EA,0x00EB,0x0113,0x0115,0x0117,0x0119,0x011B]),
15 (u"G", [0x011C,0x011E,0x0120,0x0122]),
16 (u"g", [0x011D,0x011F,0x0121,0x0123]),
17 (u"H", [0x0124,0x0126]),
18 (u"h", [0x0125,0x0127]),
19 (u"I", [0x00CC,0x00CD,0x00CE,0x00CF,0x0128,0x012A,0x012C,0x012E,0x0130]),
20 (u"i", [0x00EC,0x00ED,0x00EE,0x00EF,0x0129,0x012B,0x012D,0x012F,0x0131]),
21 (u"IJ", [0x0132]),
22 (u"ij", [0x0133]),
23 (u"J", [0x0134]),
24 (u"j", [0x0135]),
25 (u"K", [0x0136]),
26 (u"k", [0x0137,0x0138]),
27 (u"L", [0x0139,0x013B,0x013D,0x013F,0x0141]),
28 (u"l", [0x013A,0x013C,0x013E,0x0140,0x0142]),
29 (u"N", [0x00D1,0x0143,0x0145,0x0147,0x014A]),
30 (u"n", [0x00F1,0x0144,0x0146,0x0148,0x0149,0x014B]),
31 (u"O", [0x00D2,0x00D3,0x00D4,0x00D5,0x00D6,0x00D8,0x014C,0x014E,0x0150]),
32 (u"o", [0x00F2,0x00F3,0x00F4,0x00F5,0x00F6,0x00F8,0x014D,0x014F,0x0151]),
33 (u"OE", [0x0152]),
34 (u"oe", [0x0153]),
35 (u"R", [0x0154,0x0156,0x0158]),
36 (u"r", [0x0155,0x0157,0x0159]),
37 (u"S", [0x015A,0x015C,0x015E,0x0160]),
38 (u"s", [0x015B,0x015D,0x015F,0x01610,0x017F]),
39 (u"T", [0x0162,0x0164,0x0166]),
40 (u"t", [0x0163,0x0165,0x0167]),
41 (u"U", [0x00D9,0x00DA,0x00DB,0x00DC,0x0168,0x016A,0x016C,0x016E,0x0170,0x172]),
42 (u"u", [0x00F9,0x00FA,0x00FB,0x00FC,0x0169,0x016B,0x016D,0x016F,0x0171]),
43 (u"W", [0x0174]),
44 (u"w", [0x0175]),
45 (u"Y", [0x00DD,0x0176,0x0178]),
46 (u"y", [0x00FD,0x00FF,0x0177]),
47 (u"Z", [0x0179,0x017B,0x017D]),
48 (u"z", [0x017A,0x017C,0x017E])
49 ]
50 for __repchar,__codes in __corresp :
51 for __code in __codes :
52 __reptable[__code] = __repchar
53
54 @staticmethod
55 def clean(s):
56 """ enleve les accents de 's' (unicode ou utf8), et renvoi de l'unicode
57 (marche pour maj et minuscules !!!)
58 """
59 if isinstance(s,str) :
60 s = unicode(s,"utf8","replace")
61 return s.translate(Accents.__reptable)
Pages : 1