Results 1 to 6 of 6

Thread: Signal array? [SOLVED]

  1. #1
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question Signal array? [SOLVED]

    Is such a thing possible? I'd like to have an arbitrary plugin that has a vector of signals, which would directly connect to a large number of slots on stuff that it would know nothing about.

    Think of it like this:
    Qt Code:
    1. +-----------+
    2. | | +----------+
    3. | |-----| |
    4. | Object A | | Object B |
    5. | | | |
    6. | | +----------+
    7. +-----------+
    8. |
    9. |
    10. +----------------------+
    11. | |
    12. | Objects C,D,E,F,G... |
    13. | |
    14. +----------------------+
    To copy to clipboard, switch view to plain text mode 
    Basically, object A initializes a plugin (Object B), which actually acts as an input device to directly activate an "activate" slot on an a single plugin from an arbitrary-sized number of other plugins (C, D, E, F, G...). Object A would make the connections, then let the signals from B reach the appropriate slot in a given destination.

    Unfortunately, I cannot think of a way to describe this using the Qt syntax for signals and slots. Is such a thing possible?
    Last edited by KShots; 16th April 2007 at 20:00. Reason: Solved
    Life without passion is death in disguise

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal array?

    I believe it could be possible. After all, connect/disconnect take (const char*) as signal/slot names, so you should have some default names for your signals/slots.

    Could you explain more in detail what you're trying to achieve? Maybe a more particular example...

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Signal array?

    I'm not sure if I understood the explanation but QMetaObject let's you iterate through signals and slots.
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    KShots (16th April 2007)

  5. #4
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Signal array?

    Quote Originally Posted by marcel View Post
    I believe it could be possible. After all, connect/disconnect take (const char*) as signal/slot names, so you should have some default names for your signals/slots.

    Could you explain more in detail what you're trying to achieve? Maybe a more particular example...
    Ok, I'll try and give a more specific example.

    Imagine Object B is a voice activation input plugin, which would translate voice input to activate a bunch of plugins (C, D, E, F, G...) on demand, like a GPS, radio, CD player, DVD player, etc.

    Object A will look at what Object B understands by polling Objects C, D, E, F, G... for a unique tag, which will match a specific signal from B and connect as many signals that it can output (each signal is a unique activation command) directly to the appropriate plugin (Object C, D, E, F, G... if available). Basically, I'm trying to find a way to do this that will not require a re-compile of the whole project every time I add a new signal.

    EDIT: I think I may see a way via QMetaObject (thanks jpn)...

    Object A can parse all methods from Object B, looking specifically for signals:
    Qt Code:
    1. for(int index(0); index < objectB->metaObject()->methodCount(); index++)
    2. {
    3. if(objectB->metaObject()->method(index).methodType() == QMetaMethod::Signal)
    4. {
    5. // Match to a plugin from Object C,D,E,F,G...
    6. // The signal signature can be obtained from objectB->metaObject()->method(index).signature()
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by KShots; 16th April 2007 at 19:33.
    Life without passion is death in disguise

  6. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal array?

    Ok, how's this:

    ( this happens in A, which presumably has access to B and also to C, D ... )
    Qt Code:
    1. for( int i = 0; i != plugins.count(); ++i )
    2. {
    3. if( plugins[i]->tag() == objectB->currentTag() )
    4. connect( objectB, SIGNAL( activatePlugin() ), plugins[i], SLOT( activate() ) );
    5. }
    To copy to clipboard, switch view to plain text mode 
    Is this too simple? Does B has more than one signal that it needs to connect to more than one object?
    Maybe this works:
    Qt Code:
    1. for( int i = 0; i != plugins.count(); ++i )
    2. {
    3. if( plugins[i]->tag() == objectB->currentTag() )
    4. connect( objectB, SIGNAL( objectB->currentTag()->toAscii()->constData() ), plugins[i], SLOT( activate() ) );
    5. }
    To copy to clipboard, switch view to plain text mode 
    Here I assume that currentTag() returns a QString that also matches a signal name from B.


    For example if C = GPS and D = radio and E = GPS and currentTag() = GPS, then, GPS() signal from B will be connected to the activate() slots from C and E.

  7. The following user says thank you to marcel for this useful post:

    KShots (16th April 2007)

  8. #6
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Signal array?

    Hmm... I think that could also work. In this case, I'd have to define my signal signatures in some sort of function (objectB->currentTag()). In my case above, I can use QMetaObject to find the signals for me (removes some margin of error), but I'd still have to match the tags together correctly.

    Thanks!
    Life without passion is death in disguise

Similar Threads

  1. Replies: 3
    Last Post: 15th April 2007, 19:16
  2. Problem in converting QString to QChar array?
    By KaKa in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2007, 00:38
  3. Replies: 2
    Last Post: 17th May 2006, 21:01
  4. How to create QPixmap from unsigned character array?
    By rashidbutt in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 18:25
  5. no such signal QListBox::currentChanged()
    By jopie bakker in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 15:17

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.