Macau has always been leased by China to Portugal, and the ownership of sovereignty has never been disputed. The Ming Dynasty's attitude towards the Portuguese was actually similar to that of Toast, giving them a certain degree of autonomy, but they had to abide by the laws of the Ming Dynasty. Historically, there are also records of Portuguese leaders being flogged by Xiangshan County, which shows that Macao is subject to the administration of Xiangshan County.
Macao was also a window for the Ming Dynasty to understand the world, and the advanced Calendar, Mathematics and Artillery Technology of Europe flowed into the Ming Dynasty from here, promoting the development of science and technology in the Ming Dynasty. On the other hand, due to the constant war at the end of the Ming Dynasty and the growing demand for artillery, the proposal to hire Portuguese to fight was approved by the imperial court.

The person who made this suggestion was Xu Guangqi, a famous scientist in the late Ming Dynasty and a second assistant in the cabinet, who can be regarded as the highest official among the chinese scientists of all generations. After Nurhaci occupied Shenyang and other places, he began to pose a direct threat to Shanhaiguan. In order to strengthen the garrison, Xu Guangqi sent people to Macau to buy artillery and hire gunners.
In the beginning, dozens of Portuguese gunners came to China, and in Zhuozhou and other places, they fought against the Later Jin Army. They were the first European soldiers hired by the Chinese government, loyal to their duties on the battlefield, most of whom were killed or captured.
After the Manchu Qing entered the customs, the Southern Ming persisted in resistance for a long time, and the Yongli Emperor took over a mercenary army in Macau, which numbered 300. They were originally recruited by the Longwu Emperor in Macau, but the Longwu regime collapsed too quickly, and when the mercenaries were ready, they found that their employers had run away. Therefore, under the guidance of the missionaries, he turned to serve the Yongli Emperor.
In March 1647, the vanguard of the Qing army approached Guilin, they were arrogant, only a few hundred cavalry still drove straight in, without the slightest fear of the Ming army's counterattack. When the Qing army arrived at the city of Guilin, they thought that the Ming army here would flee like other cities. In fact, Yongli did escape. Only Guangxi Inspector Qu Shiyan in the city, with part of the Ming army, held firm.
Qu Shiyan ordered his Ming generals and mercenary commander Ferreira to guard the city gates. When the mercenaries spotted the Qing army, they took turns firing with artillery and arquebusiers. The armor of the Qing army could only prevent bows and arrows, and had no resistance to arquebus gun projectiles. The range of the bow and arrow in his hand was not as good as that of the arquebusier, and after firing at each other for a while, the Qing army suffered heavy casualties.
When the Qing army was overwhelmed, the mercenaries rushed out of the city gate and lined up in the popular Morris phalanx in Europe, shooting while approaching the Qing army. This phalanx consists of muskets and spears that prevent enemy troops from approaching, and muskets constantly kill and wound enemy troops. The Qing army had little strength to fight back and had to retreat.
It has to be said that at that time, europe's military theory and actual combat level had surpassed China's. Although the lead is not too much, it already has a clear advantage. It's just that the scale is too small to affect the whole war situation, and it doesn't attract enough attention.
The Ming and Qing dynasties have realized that these Red Yi are unique in military terms. But the political and economic conditions make them choose to learn from Europeans. Although the combat effectiveness of this small force is relatively strong, in the face of the superior number of Qing troops, it does not have the ability to turn things around.
Contrary to what many people think, the Qing army attaches great importance to artillery in addition to riding and shooting. It may be that in the northeast, the Hongyi cannon suffered a lot of losses, and the Qing army treated the Ming artillery that surrendered to the ming army. As a result, the Hongyi cannons that the Ming Dynasty had painstakingly bought and made were cheaper for the Qing army.
In the battle after entering the pass, it was common for the Qing army to mobilize hundreds of artillery pieces at a time, and the Ming army defending the city could not be lifted. The old-fashioned four-square walls could no longer withstand the power of artillery, not to mention that the Ming army's will to fight was getting weaker and weaker, and it often surrendered as soon as it heard the cannon.
Over the next two months, the Qing army attacked Guilin several times, but was repelled by the Ming army and Portuguese mercenaries. Although the overall scale of the battle was not large, it preserved the old nest of the Yongli Emperor and made yongli a new banner for the anti-Qing forces in the world after Longwu. The people and horses who had originally invaded the king turned to Sichuan, Hunan and other places, and the situation in Nanming seemed to have turned around.
However, the Small Imperial Court of Yongli was still unable to support Ah Dou, and constantly fought among themselves, so that the elite forces were needlessly consumed. The final fate of this Portuguese mercenary army is not recorded in various historical books, and all the people associated with them were killed.
They either disintegrate on their own or be wiped out somewhere. Although their infantry phalanx was difficult to break, as long as the Qing army concentrated enough artillery, the small phalanx of 300 people could not survive. Perhaps this is one of the reasons why European military technology did not attract enough attention from the Qing Dynasty.
By the end of the Qing Dynasty, in the face of a more advanced and powerful British army than the Portuguese mercenaries, the Qing army even turned the Ming Dynasty artillery out of the warehouse. For two hundred years, China's military technology has made little progress, and it has been left behind by Europe, at the cost of a century of humiliation.
[Reference: "Ming history", "Nanmei history"]