Results 1 to 3 of 3

Thread: How can I call a C++ function knowing its function string?

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How can I call a C++ function knowing its function string?

    Hi,

    If some one tells me there is a c++ member function, say "foo". How can I use Q_GADGET (not Q_OBJECT) to call this function?

    MyClass obj;
    obj.foo();

    However, foo is passed to me by QString "foo". The only thing I am told is that foo return void and has no argument.

    Any help is appreciated.

  2. The following 2 users say thank you to lni for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I call a C++ function knowing its function string?

    I don't think you can do that with Q_GADGET.
    At least QMetaObject::invokeMethod() always requires a QObject* as the "receiver" object.

    Cheers,
    _

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


  5. #3
    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 can I call a C++ function knowing its function string?

    Q_GADGET only provides access to class enums that are declared with Q_ENUMS. It does not make the class a QObject, provide signals/slot support, or allow you to mark a function Q_INVOKABLE.

    Quote Originally Posted by lni View Post
    If some one tells me there is a c++ member function, say "foo".
    ...
    However, foo is passed to me by QString "foo". The only thing I am told is that foo return void and has no argument.
    Unless SomeClass::foo() is static there is no way that you can call a member function without a QSomeClass object. A non-static member function has one implied argument, the pointer to the object it is to act on.

  6. The following user says thank you to ChrisW67 for this useful post:


Similar Threads

  1. Replies: 4
    Last Post: 2nd August 2012, 07:42
  2. Replies: 7
    Last Post: 9th December 2010, 22:26
  3. Qt function call in vb.net
    By abghosh in forum Qt Programming
    Replies: 7
    Last Post: 6th March 2010, 17:00
  4. function call
    By Walsi in forum Qt Programming
    Replies: 3
    Last Post: 12th June 2007, 09:13
  5. Cannot call function without object
    By Salazaar in forum Newbie
    Replies: 5
    Last Post: 11th June 2007, 14:55

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.