Hello World include Qt Gui int mainint argc

  • Slides: 30
Download presentation

Hello World #include <Qt. Gui> int main(int argc, char *argv[]) { QApplication app(argc, argv);

Hello World #include <Qt. Gui> int main(int argc, char *argv[]) { QApplication app(argc, argv); QLabel label("Hello World!"); label. show(); return app. exec(); }

Hello World - Compilation Result Run Compile

Hello World - Compilation Result Run Compile

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων l Graphics #include <QGraphics. Scene> #include <QPainter> #include <QStyle. Option>

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων l Graphics #include <QGraphics. Scene> #include <QPainter> #include <QStyle. Option> QGraphics. Scene scene; // Δηλώνει μια μεταβλητή για την σκηνή scene. set. Scene. Rect(-300, 600, 600); // Ορίζει το μέγεθος της σκηνής for (int i = 0; i < Mouse. Count; ++i) { // Βάζει ποντίκια στην λίστα Mouse *mouse = new Mouse; // Δηλώνει νέα ποντίκια mouse->set. Pos(: : sin((i * 6. 28) / Mouse. Num)*200 , : : cos((i * 6. 28) / Mouse. Num) * 200); scene. add. Item(mouse); // Βάζει τα ποντίκια στην σκηνή για να } // γίνουν render QGraphics. View view(&scene); view. set. Render. Hint(QPainter: : Antialiasing); // Δηλώνει οτι θα έχει antialiasing view. set. Background. Brush(QPixmap(": /images/cheese. jpg")); // Βάζει εικόνα για background view. set. Window. Title(QT_TRANSLATE_NOOP(QGraphics. View, "Colliding Mice")); view. resize(400, 300); view. show(); // Κάνει render την σκηνή

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων void Mouse: : paint(QPainter *painter, const QStyle. Option. Graphics. Item

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων void Mouse: : paint(QPainter *painter, const QStyle. Option. Graphics. Item *, QWidget *) { // Body painter->set. Brush(color); //Βάζει χρώμα στο brush painter->draw. Ellipse(-10, -20, 40); //Σχεδιάζει μια έλλειψη } QRect. F Mouse: : bounding. Rect() const //Συνάρτηση για bounding. Box { qreal adjust = 0. 5; return QRect. F(-18 - adjust, -22 - adjust, 36 + adjust, 60 + adjust); } void Mouse: : advance(int step) //Υπάρχουν συναρτήσεις για { set. Rotation(rotation() + dx); //rotation του αντικειμένου set. Pos(map. To. Parent(0, -(3 + sin(speed) * 3))); //και γιααλλαγή θέσης }

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων l Connecting to a Database QSql. Database db = QSql.

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων l Connecting to a Database QSql. Database db = QSql. Database: : add. Database("QSQLITE"); db. set. Database. Name(": memory: "); QSql. Query query; query. exec("create table person (id int primary key, " "firstname lastname varchar(20))"); query. exec("insert into person values(101, 'Danny', 'Young')"); model->database(). transaction(); model->database(). commit(); model->database(). rollback(); – – varchar(20), Ξεκινούμε συναλλαγή (transaction ) με το database χρησιμοποιώντας την συνάρτηση QSql. Database: : transaction(). Το database transaction είναι μία μονάδα αλληλεπίδρασης με το database management που αντιμετωπίζεται με συνεπή και αξιόπιστο τρόπο, ανεξάρτητο από άλλες συναλλαγές. Με το commit() αποθηκεύουμε όλες τις αλλαγές στο database. Ενώ με το rollback() επαναφέρουμε την προηγούμενη κατάσταση του database, πριν τις αλλαγές.

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων l Sockets #include <Qt. Network> void Fortune. Thread: : run()

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων l Sockets #include <Qt. Network> void Fortune. Thread: : run() { QString server. Name = host. Name; quint 16 server. Port = port; //Δηλώνει ένα port while (!quit) { const int Timeout = 5 * 1000; QTcp. Socket socket; //Δηλώνει το socket. connect. To. Host(server. Name, server. Port); If (!socket. wait. For. Connected(Timeout)) { //To socket περιμένει νέα σύνδεση emit error(socket. error(), socket. error. String()); //Αν κάνει timeout στέλνει return; } // μήνυμα λάθους και τερματίζει while (socket. bytes. Available() < (int)sizeof(quint 16)) { if (!socket. wait. For. Ready. Read(Timeout)) { emit error(socket. error(), socket. error. String()); return; } } }

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων l Threads #include <QThread> //for thread functions #include <QMutex> //for

Παρουσίαση Δυνατοτήτων Μέσω Παραδειγμάτων l Threads #include <QThread> //for thread functions #include <QMutex> //for the use of mutexes #include <QWait. Condition> //for synchronising threads //To execute it create an instance of My. Thread and call the start() method. class My. Thread : public QThread { protected: void run(); }; void My. Thread: : run() //implement the code that you want the thread to run { QMutex mutex; QWait. Condition condition; mutex. lock(); //use of mutexes condition. wait(&mutex); count ++; mutex. unlock(); condition. wake. All(); //wakes all the threads that are in a wait state }

Συμπεράσματα Υλοποίησης του Προγράμματος Επίδειξης l Δήλωση και δημιουργία των αντικειμένων που υπάρχουν στη

Συμπεράσματα Υλοποίησης του Προγράμματος Επίδειξης l Δήλωση και δημιουργία των αντικειμένων που υπάρχουν στη φόρμα: QPush. Button *ui_find. Button; //the find button QText. Edit *ui_text. Edit; //the textbox containing the lexicon QLine. Edit *ui_line. Edit; //the textbox containing the search word bool is. First. Time; //to check if the word was found more than once ui_find. Button = q. Find. Child<QPush. Button*>(this, "find. Button"); ui_text. Edit = q. Find. Child<QText. Edit*>(this, "text. Edit"); ui_line. Edit = q. Find. Child<QLine. Edit*>(this, "line. Edit");

Συμπεράσματα Υλοποίησης του Προγράμματος Επίδειξης void Text. Finder: : load. Text. File() { QFile

Συμπεράσματα Υλοποίησης του Προγράμματος Επίδειξης void Text. Finder: : load. Text. File() { QFile input. File(": /forms/input. txt"); //where to get the lexicon from input. File. open(QIODevice: : Read. Only); QText. Stream in(&input. File); QString line = in. read. All(); //copy the lexicon in the line string input. File. close(); //fill the textbox with the contents of line string (i. e. the lexicon) ui_text. Edit->append(line); ui_text. Edit->set. Undo. Redo. Enabled(false); ui_text. Edit->set. Undo. Redo. Enabled(true); }

Συμπεράσματα Υλοποίησης του Προγράμματος Επίδειξης cursor. begin. Edit. Block(); //set the highlight preferences QText.

Συμπεράσματα Υλοποίησης του Προγράμματος Επίδειξης cursor. begin. Edit. Block(); //set the highlight preferences QText. Char. Format plain. Format(highlight. Cursor. char. Format()); QText. Char. Format color. Format = plain. Format; color. Format. set. Foreground(Qt: : red); //find the search word in the lexicon while (!highlight. Cursor. is. Null() && !highlight. Cursor. at. End()) { highlight. Cursor = document->find(search. String, highlight. Cursor, QText. Document: : Find. Whole. Words); // highlight the word as defined above if (!highlight. Cursor. is. Null()) { found = true; highlight. Cursor. move. Position(QText. Cursor: : Word. Right, QText. Cursor: : Keep. Anchor); highlight. Cursor. merge. Char. Format(color. Format); } } cursor. end. Edit. Block();

Βιβλιογραφία l l http: //www. wikipedia. org/ http: //qt. nokia. com/ http: //code. google.

Βιβλιογραφία l l http: //www. wikipedia. org/ http: //qt. nokia. com/ http: //code. google. com/p/android-lighthouse/ Documentation μέσα στο toolkit.