QT Notes - Event Processing

What is 1 event

The main event here is the user input events, such as clicking a button, check the box and so on. When an event occurs, we achieve satisfactory results.

2 signals and slots

connect(A,XX,B,YY)

When the incident occurred A, B in the handler will be called

3 Case ideas

(1) through the document to find the signal control event. such as

QPushButton => QAbstractButton found in a parent class

void clicked(bool checked=false)

(2) defines a handler

//head File

private slots:

  int OnShowClicked(bool checked);

// cpp file

int TEST::OnShowClicked(bool checked)

{

  return 0;

}

(3) b and the signal event object A linked object slot

connect(ui.btnShow,SIGNAL(clicked(bool)),this,SLOT(OnShowClicked))

4 real case

(1) QT Creator to create a project to realize click the button, a "Chinese" in the following text box

File ---> New Project ----> QT widgets Application ----> project name -> Next project is structured as follows

(2) Click below ui file Forms 

Modify the variable name (automatically generated code)

 

 

 Right-click the control ----> Go trough ----> select signal ---> function corresponding write

 

 (3) write handlers

 

 (4) the button and associate events

 

 ok, this way is complete.

 

Guess you like

Origin www.cnblogs.com/lanjianhappy/p/11728465.html