简体   繁体   中英

How can I connect two objects from different windows in Qt?

I have a window1 which has 2 buttons, one add button and a next button.

The add button is initially disabled. Once clicked on next button, a new window2 is opened. On that window there is a OK button.

I want to enable the add button from window1 after clicking on the OK button from window2 .

Is it possible to connect two objects ( signal & slot ) from diffrent windows? If yes, where ( on which .cpp file ) do I have to write the connect function?

Of course you can connect a signal from one object to a slot in a different object - otherwise the functionality wouldn't be very useful.

You can either do the connection outside either object in some code that has access to both, or you can pass a pointer of/to one of the objects to the other and then do the connection inside the other object. What makes the most sense depends on how your code is structured.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM