Qt Script Tetrix ExampleThe QSTetrix example is a Qt Script version of the classic Tetrix game. The program logic in this example is a fairly straight port of the logic in the C++ Tetrix Example. You may find it useful to compare the implementations of the TetrixBoard, TetrixPiece and TetrixWindow classes to see how Qt Script is used to implement methods, call Qt functions, and emit signals. The graphical user interface is defined in a UI file, created using Qt Designer, and is set up in the example's C++ main.cpp file. We define a custom UI loader that handles our TetrixBoard widget; this is the main component of the UI (where the pieces are drawn). We initialize the script engine to have the Qt namespace, so that e.g., Qt.Key_Left will be available to script code. We also make the application object available (for the quit() slot). Several scripts are evaluated as part of the engine setup process. The tetrixpiece.js file contains the definition of the TetrixPiece class, which is used to populate the play field. The tetrixboard.js file contains the definition of the TetrixBoard class, which contains the main game logic. Finally, tetrixwindow.js contains the definition of the TetrixWindow class, which wires up the top-level widget. A form is created from the UI file. A new TetrixWindow script object is then constructed, passing the form as its argument. The form is shown, and the event loop is entered. Files: |