PDA

View Full Version : How to connect to a unknown class object signal?



wshn13
20th March 2012, 01:39
Now I am develope a lib ,the lib can be used in various apps .But a problem come that the lib have to konw or just say connect some signal interested of the apps,the object which can emit the signal interested is not a certain type ,for example ,in app1 the object may be a class1 ,in app2 the object may be class2, so how to connect a certain signal without konw the detial of the object ?

ChrisW67
20th March 2012, 02:31
I don't see an issue, have the app connect its signal to the library class slot.


how to connect a certain signal without konw the detial of the object ?
That is the purpose of the header file that defines a class. Are you saying that you do not have access to the header defining classes in the library?

wshn13
20th March 2012, 03:02
I don't see an issue, have the app connect its signal to the library class slot.


That is the purpose of the header file that defines a class. Are you saying that you do not have access to the header defining classes in the library?

Yes ,I have no access to the header files .Now I can get the method and signal list of the object which I don't konw the class type by using the QMetaObject ,but the problem now is how to connect at run time .

ChrisW67
20th March 2012, 03:46
How do you intend to create instances of the unknown classes from the undocumented library? You need instances before you can connect anything.

wshn13
20th March 2012, 05:11
How do you intend to create instances of the unknown classes from the undocumented library? You need instances before you can connect anything.

My project aimed to make a lib based on Qt,this lib can be used into various apps ,I can't have access to the app's document which use the lib ,but I have a instance of some class in the app ,so this is the problem .

ChrisW67
20th March 2012, 05:57
I think you are looking at this the wrong way around. There are no unknowns to deal with here.

Your library cannot, and does not need to, know anything about the internals of the application that is using it. The application must know about the library it is using in order to be able to use it. Your library publishes its interfaces in the form of headers files and the library itself. The application can use that information link to, instantiate and use objects from the library (and perform signal/slot connections for QObjects). If functions in your library need objects passed in from outside then these objects must present interfaces known to (e.g. implements QAbstractItemModel) or defined and exported by the library.

wshn13
20th March 2012, 06:56
I think you are looking at this the wrong way around. There are no unknowns to deal with here.

Your library cannot, and does not need to, know anything about the internals of the application that is using it. The application must know about the library it is using in order to be able to use it. Your library publishes its interfaces in the form of headers files and the library itself. The application can use that information link to, instantiate and use objects from the library (and perform signal/slot connections for QObjects). If functions in your library need objects passed in from outside then these objects must present interfaces known to (e.g. implements QAbstractItemModel) or defined and exported by the library.

Thanks for your suggestion ,right now I just pursue the lib's compatible ,wrong as you say .I will recode it.