Results 1 to 2 of 2

Thread: Qt signal adapter library

  1. #1
    mwilson is offline Registered User
    Name: Mark Wilson
    Organization: University of Rochester
    Project: Omega EP laser
    Join Date
    Jul 2005
    Location
    Rochester, NY
    Posts
    100

    Qt signal adapter library

    I have released QtSignalAdapters to https://sourceforge.net/projects/qtsignaladapter/.

    While not directly related to Ice, it seems that a lot of Ice fans use Qt, so I thought it might prove useful to some of you.

    QtSignalAdapters makes it easy to connect a Qt signal to class methods, stand-alone functions, and function objects. The library is header only, and depends on Boost (www.boost.org).

    An example will help explain what QtSignalAdapters is for. Let's say we have a slice file:

    Code:
    module Motors
    {
       interface MotorControl
       {
            void setMotorMoveCounts(int motorCounts);
            void move();
       };
    };
    We can connect a QtPushButton directly to the move method, and a QSpinBox directory to the setMotorMoveCounts method, of a MotorControlPrx:

    Code:
    connect0<void()>(pushButton, SIGNAL(clicked()),
       boost::bind(&IceProxy::Motors::MotorControl::move, motorControlPrx_.get());
    
    connect1<void(int)>(spinBox, SIGNAL(valueChanged(int)),
        boost::bind(&IceProxy::Motors::MotorControl::setMotorMoveCounts, motorControlPrx_.get(), _1));
    The library provides connect methods for zero to five parameters, and the parameters can be any types. See the TestQt2Func subdirectory for another example. The adapters that are created by the connectX methods are made children of the QObject (pushButton, spinBox), so that when those objects are deleted, the adapter is also deleted.
    Mark E. Wilson
    Lead Programmer/Analyst
    Omega EP Project
    Laboratory for Laser Energetics (www.lle.rochester.edu)
    University of Rochester
    Rochester, NY 14623

  2. #2
    mwilson is offline Registered User
    Name: Mark Wilson
    Organization: University of Rochester
    Project: Omega EP laser
    Join Date
    Jul 2005
    Location
    Rochester, NY
    Posts
    100
    That should have been "a QSpinBox directly" after the first code block.

    In the example, the "motorControlPrx_.get()" returns a raw pointer to the proxy. This does not increase the reference count of the smart pointer proxy object. This shouldn't be a problem as long as some entity holds the proxy object and the proxy doesn't change. If you want boost::bind to hold a reference to the proxy, check out the posting:

    boost::shared_ptr

    So for the MotorControl example, you would add this snippet somewhere (this would be very easy for slice2cpp to generate):

    Code:
    namespace IceProxy
    {
    namespace Motors
    {
        template<class T> inline T* get_pointer(
            IceInternal::ProxyHandle<T> const & p)
        {
            return p.get();
        }
    }
    }
    Boost::bind is written to handle boost::shared_ptr specifically, but defining this function template allows the IceUtil smart pointer to be held by boost::bind....
    Mark E. Wilson
    Lead Programmer/Analyst
    Omega EP Project
    Laboratory for Laser Energetics (www.lle.rochester.edu)
    University of Rochester
    Rochester, NY 14623

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. New Ice 3.4.0 AMI and Qt 4.5 library
    By mwilson in forum Projects
    Replies: 0
    Last Post: 08-12-2010, 03:58 PM
  2. Ice 3.4.0 and GUI QT library
    By marcel in forum Bug Reports
    Replies: 2
    Last Post: 03-11-2010, 06:08 PM
  3. Program received signal SIG34
    By luansxx in forum Bug Reports
    Replies: 1
    Last Post: 09-15-2006, 06:07 AM
  4. signal handling and ice::Application
    By fitzharrys in forum Help Center
    Replies: 11
    Last Post: 10-18-2005, 05:51 PM
  5. How to trap signal in ICE::Service Class
    By dragzhb in forum Help Center
    Replies: 6
    Last Post: 09-15-2004, 10:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •