Results 1 to 7 of 7

Thread: How to connect to a unknown class object signal?

  1. #1
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to connect to a unknown class object signal?

    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 ?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect to a unknown class object signal?

    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?

  3. #3
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to connect to a unknown class object signal?

    Quote Originally Posted by ChrisW67 View Post
    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 .

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect to a unknown class object signal?

    How do you intend to create instances of the unknown classes from the undocumented library? You need instances before you can connect anything.

  5. #5
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to connect to a unknown class object signal?

    Quote Originally Posted by ChrisW67 View Post
    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 .

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect to a unknown class object signal?

    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.

  7. #7
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to connect to a unknown class object signal?

    Quote Originally Posted by ChrisW67 View Post
    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.

Similar Threads

  1. Replies: 11
    Last Post: 7th October 2011, 04:53
  2. Replies: 12
    Last Post: 30th December 2010, 10:37
  3. Mysql unknown database, QMYSQL unable to connect
    By lixo1 in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2010, 21:39
  4. Connect signal from base to slot of sub-sub-object
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 30th October 2008, 19:54
  5. Replies: 12
    Last Post: 18th September 2008, 15:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.