VS&QT-Qt Creator has no option to go to slot

problem

Problem statement

Solution

living comfortably without anybody's help

//xxx.h
signals:
	xxx
private slots:
	xxx
//xxx.cpp
connect(xx,xx,xx,xx);

semi-automatic

It is definitely difficult to adapt to this when used to go to the slot function, and I find it particularly troublesome. In fact, we have a relatively concise method.

It only needs to be standardized!

For example, I need to add a pushButton click event:

// xxx.h
private slots:
	void on_pushButton_DigitalIO_clicked();
// xxx.cpp
void xxxx::on_pushButton_DigitalIO_clicked(){
    
    
	//...
}

It was found that this method was caused by an accident. The custom slot function was always called twice, and the signal was only sent once. In the end, it was found that the slot function name was a problem.

So I started thinking, we clicked to go to the slot, QT Creatorwhat did we do for us?

Let me talk about the conclusion first, it Qt Creatorwill help us generate a slot function named in a specific format; when compiling, it is done internally according to the naming rules connect.

Specifically:

  • Modify ui文件, compile and generateui_xxxx.h
  • ui_xxxx.hContains setupUint( )the function, there must be the end of the functionQMetaObject::connectSlotsByName(HardwareControl)

Let's look on the Qtofficial explanation of the document:
Insert picture description here
This function recursively search all child objects of a given object, and from their match signal to follow certain rules of the object bench.

According to the rules, we just need to define the channel function can be, connectlet Qtto complete it -

void on_<object name>_<signal name>(<signal parameters>);

Guess you like

Origin blog.csdn.net/weixin_40774605/article/details/108086349