Академический Документы
Профессиональный Документы
Культура Документы
Workbook
Version 2.0
Prerequisities
The participants should have knowledge on C++ language with basic object oriented features including classes and object, inheritance and virtual methods. Template principles are needed only for understanding Qts collection classes. No STL or RTTI (runtime-type-information) knowledge of standard C++ required.
In this exercise we implement an application, which calculates the fuel costs of a car trip. The inputs are fuel consumption (liters/100kms), fuel cost per liter and trip distance. The basic application GUI could consist of e.g. QLabels, QLineEdits and a QPushButton but use here some other input widgets like sliders or dial components. Implement the GUI your own main widget class deriving from QWidget. In the main method you just initialize the application and create an instance of your widget. a) Create an empty Qt4 project TripCostCalculator for your application by using Qt Creator. b) Write a header file tripcostcalculator.h for your application: #include <QWidget> #include <QLabel> // etc class TripCostCalculator: public QWidget { Q_OBJECT public: TripCostCalculator (QWidget *parent = 0); ~ TripCostCalculator(); private: QLabel* consLabel; // etc other widgets youll need }; c) Create and write a source file tripcostcalculator.cpp for your widget and implement the widget d) Create a main.cpp file where you create QApplication instance, create and show your widget and execute the application. e) Build and Run
a) In your main widget, add a slot calculateTripCost() b) Connect the signal emitted by QPushButton to your slot where you calculate the trip cost and show the result in the result label. You can access the user input texts of QLineEdit components by invoking text(). The method returns the as a QString, which then must be converted to number for the calculation. c) Build and run the application d) Try debugging the application by setting breakpoints and running the code line by line exploring the varialbes. Optional (time permitting) Write a signal to your widget and slot for the signal. Test your signal-slot implementation with no parameters and by passing some data across the objects (e.g. an integer).
Workshop: Innovate and implement your own mobile application! At least start with your idea!