Tutorial · Chapter 2

First Project — Logging from a Button Click

Create a new project and complete the simplest possible example: place one button on the screen, and when it is pressed, print a log 10 times using a for loop. By following this process, you will learn the core development flow of QMachineStudio all at once — lay out the screen → connect the event to a function → write code in the function → run → check the log.

QMachineStudio does not work by directly editing text files; instead, you add functions and steps in the Solution Explorer tree and edit only the code of the selected item. If this concept is unfamiliar, read the "Development Approach" section of Getting Started first.

1. Create the Project

  1. Create a new project with File → New. Name it FirstProject.
  2. When creation finishes, a View module that holds the screen and a Run module that holds the operation are created together in the Solution Explorer. This example uses only the screen (View) module.

2. Add a Button to the Screen

  1. In the Solution Explorer, double-click the screen item of the View module to open the designer (View Module).
  2. Drag a Button from the control palette onto the screen. You can find the available control types in the UI Controls Reference.
  3. Select the button and set its display text (e.g., Run Log) and name (e.g., btnRunLog).

3. Connect the Button Click to a Function

The action to run when the button is pressed is written as a function, and that function is connected to the button's click event. For a button click to call a function in QMachineStudio, the button's Action property must be RunEvent.

  1. With the button selected, set the Action property to RunEvent in the Property Editor on the right. The default value of Action is None, and the OnClickEvent function runs on click only when it is RunEvent. If you leave it on another value such as ShowPage or RunManual, the click is handled as that action and OnClickEvent is not called.
  2. With Action set to RunEvent, double-click the button. If the function specified in OnClickEvent (under the XMachineEvent group) does not yet exist, the function is created automatically and its editing tab opens. (To name the function yourself, first enter a name such as OnRunLogClick in the OnClickEvent property, then double-click.)
  3. The function created this way is added as a node under the Functions of the corresponding View module in the Solution Explorer. Later, you can right-click the node to Rename · Delete it.

When called, the event function automatically receives the button name, tag, and so on (string sender, int tag, array params). This example does not use the arguments.

4. Write the Log with a for Loop

Write the following code in the open function editing tab. Declare a variable i, and use for to repeat from 1 to 10, leaving one log line each time.

xscript
int i;
 
for(i, 1, 10)
{
    Log("count = {0}", i);
}
  • for(variable, start, end) is a range-based loop that includes the end value. The code above repeats a total of 10 times with i going from 1 to 10.
  • Log("...{0}...", value) outputs a log, and the trailing value is inserted at the {0} position. Here, 10 lines are output, from count = 1 to count = 10.

5. Build and Run

  1. Save and build with Build → Save All & Make (F6). Check that there are no errors in the Output panel at the bottom. (For the result panels, see Output · Error · Search.)
  2. Start the runtime with Build → Run (F5). The screen you created runs.
  3. Press the Run Log button on the screen.

6. Check the Log with Log Manager

When you press the button, Log("count = {0}", i) runs and 10 log lines are left. These runtime logs are checked with the companion tool, ICT Log Manager.

  1. Run Log Manager and start live reception, or open a saved log file. (For details, see Log Manager Overview and Live Logs · Opening Files.)
  2. If you see 10 lines in order from count = 1 to count = 10 in the log list, you have succeeded.
  3. When there are many lines, you can quickly check by searching for count with Log Manager's Search · Filter.

What You Learned

  • How to place a control on the screen (View) and, by setting the button Action to RunEvent, connect its click event (OnClickEvent) to a function
  • The QMachineStudio development approach of adding a function as a node in the tree and editing only that node's code
  • The range-based for(i, 1, 10) loop and Log("...{0}...", value) output
  • How to check runtime logs with Log Manager

Next Steps