Results 1 to 12 of 12

Thread: Saving state of connections

  1. #1
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Saving state of connections

    I have an app I'm working on which makes signal/slot connections by drag/dropping objects. To complicate things, it makes connections between plugins. This part works well now, but I can't figure out a way to save the state of connections. I somehow need a list of connections so I can save the parameters with QSettings. Anyone have an idea how I can do this?

    The closest I can find is using connectNotify() which could create a list. But that means I would also have to use disconnectNotify(), and write lots more code in each plugin.

    dumpObjectInfo() sounds close to what I want, but it sends it to debug output, and probably has a lot more info than I need.

  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: Saving state of connections

    QObject::metaObject() returns a pointer to its QMetaObject.

    With QMetaObject (QMetaObject::method())you can get a list of signals and slots and also query the connections. You can find more in the documentation.

    Regards
    Last edited by marcel; 15th August 2007 at 06:20.

  3. #3
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving state of connections

    Quote Originally Posted by marcel View Post
    With QMetaObject (QMetaObject::method())you can get a list of signals and slots and also query the connections. You can find more in the documentation.
    I see how it gives info on signals and slots, but the documentation says nothing about connections.

    Do you know of somewhere this is used? I'd like to look at some code using this.

  4. #4
    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: Saving state of connections

    Look in a generated moc in the implementation of a signal, and see how the slot gets called.

    Regards

  5. #5
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving state of connections

    Quote Originally Posted by marcel View Post
    Look in a generated moc
    Well, that doesn't seem to help me. I'll need to generate the list myself either way, so I think I'll start with (dis)connectNotify(), as all the information should be available when thats called. It would speed up the saving procedure, but add some time to the loading procedures.

    Thanks for the help, I may still end up following those suggestions. I'll see where it goes.

  6. #6
    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: Saving state of connections

    Quote Originally Posted by Chuk View Post
    Well, that doesn't seem to help me. I'll need to generate the list myself either way, so I think I'll start with (dis)connectNotify(), as all the information should be available when thats called. It would speed up the saving procedure, but add some time to the loading procedures.

    Thanks for the help, I may still end up following those suggestions. I'll see where it goes.
    I think you will have to use your solution and keep a local connection list.

    QObject uses two private classes to store connections: QConnection and QConnectionList.
    These two are not accessible in any way.

    Regards

  7. #7
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving state of connections

    Quote Originally Posted by marcel View Post
    QObject uses two private classes to store connections: QConnection and QConnectionList.
    These two are not accessible in any way.
    They aren't even in the documentation. Otherwise I would try to subclass them.

  8. #8
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving state of connections

    Well, connectNotify() doesn't seem to work for this. It's just a function, and sender() is not available. The closest useful thing is receivers(), but that only returns a count. I guess my approach now is to use my own connect() function, such as connectChannels() with the same parameters, have that function keep the list of connections made.

  9. #9
    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: Saving state of connections

    I guess my approach now is to use my own connect() function, such as connectChannels() with the same parameters, have that function keep the list of connections made.
    But it is not the function that holds the connection list, it is a class - QObject.

  10. #10
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Saving state of connections

    I don't think tricking the signal/slot system is the answer. I see two kinds of connections here. The theoretical higher-level connections between your plugins and the relatively lower-level Qt signal/slot connections.

    Every drag/drop, I would save a stringifiable (meaning: able to be stringified) representation of the new higher-level connection as well as connect the signal and slot. You can save the higher-level connections in QSettings and upon restart, restore the signal/slot connections from that.

    Even if it is a one-on-one mapping, it would be the more elegant solution.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  11. #11
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving state of connections

    Quote Originally Posted by Michiel View Post
    I don't think tricking the signal/slot system is the answer.
    I'm not tricking it, I just moved the location of the call to connect(). Docs for connectNotify() say "Warning: This function violates the object-oriented principle of modularity." which seems more like tricking it.

    Quote Originally Posted by Michiel View Post
    Every drag/drop, I would save a stringifiable (meaning: able to be stringified) representation of the new higher-level connection as well as connect the signal and slot.
    Thats exactly what I did. The following function is called for every drop, if accpeted, and is also used to restore connections.

    Qt Code:
    1. QMultiMap<QString, QString> connections;
    2.  
    3. void Core::connectChannels(Channel* sender, Channel* receiver)
    4. {
    5. connections.insert(sender->getModName() + "|" + sender->getName(), receiver->getModName() + "|" + receiver->getName());
    6.  
    7. connect(sender, SIGNAL( Output(QString) ), receiver, SLOT( Input(QString) ));
    8. }
    To copy to clipboard, switch view to plain text mode 

    This does require every object to have a unique name, but that doesn't seem unreasonable. To save the list, I just iterate through connections and pass the strings to QSettings(). To restore connections, I have search functions that return pointers to the channel by seraching on the ModName and Channel Name.

    The Core class is what loads the plugins, and restores their state, and has the lists of objects that can be connected. So it seems like the best place to handle the connections.

  12. #12
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Saving state of connections

    My apologies. I didn't read the thread carefully enough. I see you already came up with this idea in post #8.

    Looks good.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

Similar Threads

  1. [QT4] Saving a widget state
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2006, 15:31

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.