Results 1 to 5 of 5

Thread: Invoke a slot by its name in QString...

  1. #1
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Invoke a slot by its name in QString...

    Hi,

    Suppose there is a slot called a foo() in my DerivedFromQObject class;
    I will have a QObject* ptr pointing to the DerivedFromQObject
    I need to extract the Slots for the DerivedFromQObject's obj.
    and ivoke its slot at run time. It's just like a plugin.
    We can't solve problems by using the same kind of thinking we used when we created them

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Invoke a slot by its name in QString...

    Hi,

    I wonder if you can do this.

  3. #3
    Join Date
    Feb 2006
    Location
    Boulder, Colorado, USA
    Posts
    63
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Invoke a slot by its name in QString...

    Try using
    const QMetaObject * QObject::metaObject () const

    Check out the docs for QMetaObject it should give you what you need

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Invoke a slot by its name in QString...

    Quote Originally Posted by sunil.thaha
    Hi,

    Suppose there is a slot called a foo() in my DerivedFromQObject class;
    I will have a QObject* ptr pointing to the DerivedFromQObject
    I need to extract the Slots for the DerivedFromQObject's obj.
    and ivoke its slot at run time. It's just like a plugin.
    Dynamic signals and slots

  5. #5
    Join Date
    Feb 2006
    Location
    Boulder, Colorado, USA
    Posts
    63
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Invoke a slot by its name in QString...

    I haven't tried this but something like this might work:

    Qt Code:
    1. DerivedObj * myDerivedObj = new myDerivedObj();
    2. if (myDerivedObj->metaObject()->indexOfSlot( "slotName" ) != -1)
    3. {
    4. QMetaObject::invokeMethod ( myDerivedObj, "slotName", Qt::DirectConnection);
    5. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  2. easiest Way QString can do
    By baray98 in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2008, 20:49
  3. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  4. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  5. How to create custom slot in Qt Designer 4.1?
    By jamadagni in forum Qt Tools
    Replies: 31
    Last Post: 18th January 2006, 20:46

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.