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 Explorertree 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
- Create a new project with
File → New. Name itFirstProject. - When creation finishes, a
Viewmodule that holds the screen and aRunmodule that holds the operation are created together in theSolution Explorer. This example uses only the screen (View) module.
2. Add a Button to the Screen
- In the
Solution Explorer, double-click the screen item of theViewmodule to open the designer (View Module). - Drag a
Buttonfrom the control palette onto the screen. You can find the available control types in the UI Controls Reference. - 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.
- With the button selected, set the
Actionproperty toRunEventin theProperty Editoron the right. The default value ofActionisNone, and theOnClickEventfunction runs on click only when it isRunEvent. If you leave it on another value such asShowPageorRunManual, the click is handled as that action andOnClickEventis not called. - With
Actionset toRunEvent, double-click the button. If the function specified inOnClickEvent(under theXMachineEventgroup) does not yet exist, the function is created automatically and its editing tab opens. (To name the function yourself, first enter a name such asOnRunLogClickin theOnClickEventproperty, then double-click.) - The function created this way is added as a node under the
Functionsof the correspondingViewmodule in theSolution Explorer. Later, you can right-click the node toRename·Deleteit.
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.
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 withigoing 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, fromcount = 1tocount = 10.
5. Build and Run
- Save and build with
Build → Save All & Make(F6). Check that there are no errors in theOutputpanel at the bottom. (For the result panels, see Output · Error · Search.) - Start the runtime with
Build → Run(F5). The screen you created runs. - Press the
Run Logbutton 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.
- Run Log Manager and start live reception, or open a saved log file. (For details, see Log Manager Overview and Live Logs · Opening Files.)
- If you see 10 lines in order from
count = 1tocount = 10in the log list, you have succeeded. - When there are many lines, you can quickly check by searching for
countwith Log Manager's Search · Filter.
What You Learned
- How to place a control on the screen (
View) and, by setting the buttonActiontoRunEvent, 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 andLog("...{0}...", value)output - How to check runtime logs with Log Manager
Next Steps
- Run Module — Build operation logic with variables · functions · sequences · steps
- View Module — Screen designer and data binding
- XScript Language Basics — Variables · functions · control statements
- Log Manager — Log analysis tool