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.
Note QMachineStudio does not work by editing text files directly; 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
- Choose File → New, or press New Project on the Welcome page.
- In the NEW PROJECT DIALOG, enter
FirstProjectinProject Nameand the folder to hold the project (e.g.D:\RUN) inProject Path, then press OK. You can also pick the folder with the...button. - A
FirstProjectfolder is created underProject Path, filled from the default template, and the new project opens right away. If another project was open, it is closed first and you are asked whether to save it.
The Solution Explorer of a new project contains the modules below. There is no run module (sequence) yet.
| Group | Module | Role |
|---|---|---|
| System Modules | Mon · Event · Data · Init | Monitoring · common event functions · variables · machine initialization |
| View Modules | ViewMain | Main window of the machine screen (MainView of the project options) |
| View Modules | ViewRun | Run page shown in BasePanel of the main window when the machine screen opens (START · STOP · RESET buttons) |
In this example you place the button on ViewRun, the screen you see as soon as the machine screen opens.
2. Add a Button to the Screen
- In the Solution Explorer, double-click View Modules → ViewRun → Design to open the screen designer (View Module).
- Drag
Buttonfrom theButtongroup of the ToolBox at the bottom left of the designer onto the screen. You can find the available control types in the UI Controls Reference. - With the button selected, enter the display text (e.g.
Run Log) inCaptionand the name (e.g.btnRunLog) inNameof the Property Editor at the top left.

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 (OnClickEvent).
For a button click to call a function, the button's Action property must be RunEvent.
- Double-click the button in the designer.
- If
Actionis the defaultNoneorRunEvent, QMachineStudio creates a click event function underFunctionsofViewRun, puts its name intoOnClickEventand changesActiontoRunEvent. The function's editing tab opens right away. - When
OnClickEventis empty, the function is namedButtonName_OnClickEvent. In this examplebtnRunLog_OnClickEventis created. To choose the name yourself, enter it (e.g.OnRunLogClick) in theOnClickEventproperty before double-clicking. - The function is added as a node under
ViewRun → Functionsin the Solution Explorer. Later you can right-click the node to Rename Function · Delete Function. When you rename it, update the button'sOnClickEventas well.
Caution If
Actionhas another value such asShowPage, the click is handled as that action and theOnClickEventfunction is not called. In that case double-clicking does not changeActionand only shows a notice (RunFunction·RunManualopen the specified function in the editor). Screen events can call only functions of the same view module, so the event function must be inViewRun.
When called, the event function receives string sender (control name), int tag (the control's TagIndex) and array params.
This example does not use the arguments.
4. Write the Log with a for Loop
In the open function tab, add code above return true;. Declare a variable i and use for to repeat from 1 to 10,
leaving one log line each time. The finished function looks like this.
FUNCTION bool btnRunLog_OnClickEvent(string sender, int tag , array params)
{
// ==========================================================================
// Module : 'ViewRun'
// ( header comment inserted automatically )
// ==========================================================================
int i;
for(i, 1, 10)
{
Log("count = {0}", i);
}
return true;
}for(variable, start, end)is a range-based loop that includes the end value. The code above runs 10 times withigoing from 1 to 10. See Control Flow for the full syntax.Log("...{0}...", value)outputs a log, and the trailing value is inserted at{0}. The interpolated formLog($"count = {i}")works the same. Here 10 lines are output, fromcount = 1tocount = 10.- New functions are created with a
boolreturn type, so keep the finalreturn true;.
5. Build and Run
- Save and build with Build → Save All & Make (
F6). If there are errors, the Error List tab at the bottom opens automatically, and double-clicking an item jumps to its location. (For the bottom pane, see Output · Error · Search.) - Build → Run (
F5) saves, builds and switches to the machine screen. TheViewRunscreen appears inside the main window (ViewMain). - Press the
Run Logbutton on the screen.
To return from the machine screen to the development screen, log in as Developer and press Ctrl+F5.
The machine screen and simulation mode are described in Run Modes.
Note When testing on a PC without motor or IO boards, turn on Simulation mode on the Options tab of the project options; IO and motors then run as virtual devices.
6. Check the Log with Log Manager
Pressing the button runs Log("count = {0}", i) and leaves 10 log lines. QMachineStudio sends runtime logs to the companion tool
ICT Log Manager, so Log Manager must be running before you press the button.
Logs produced while Log Manager is not running are not kept.
- Start Log Manager. On the machine screen of a new project, the
LOGbutton (ActionShowLogManager) brings the running Log Manager window to the front. (For details, see Log Manager Overview and Live Logs · Opening Files.) - If you see 10 lines in order from
count = 1tocount = 10in the Live tab, you have succeeded. - When there are many lines, search for
countwith Log Manager's Find · Bookmarks · Filter Bar.
What You Learned
- How to create a new project and what the default modules (System Modules ·
ViewMain·ViewRun) do - How to place a control on a view module and create and connect a click event function by double-clicking the button (
Action=RunEvent) - The QMachineStudio approach of managing functions as nodes 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
- Database Tutorial — handling SQLite data from screen buttons
- Log Manager — log analysis tool