Regarding Qt calling multiple/twice setupUi, the automatic connection between signal and slot fails

Code scene:

The function calls setupUi okBtn twice inside the function insert image description here
and the automatic connection slot function fails
insert image description here

problem analysis:

Such a function is called inside the setupUi function: connectSlotsByName
Judging from the function name, it is to connect the signal and the slot through the name (component name)
insert image description here
Explanation of the official document:
insert image description here
So the process should be like this:
The setupUi function will have a new resource inside, and the new resource will be called twice Twice, it involves the duplication of component object names. At this time, there are two okBtn. The connection method is to recursively retrieve the component object names. The first okBtn that is always connected appears, so the second okBtn is not connected, resulting in no effect ( Of course, you can use the connect function directly to connect normally, because it is through the memory to find the corresponding component connection )

Guess you like

Origin blog.csdn.net/TheKoi/article/details/129931171