Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED]Function pointer
QtWS25 Last Chance

[SOLVED]Function pointer

Scheduled Pinned Locked Moved C++ Gurus
9 Posts 4 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qxoz
    wrote on last edited by
    #1

    Hi gurus!
    How i can do something like this:

    This is the class that stores data item and it has a pointer to function for some manipulation with data
    @class VariableItem
    {
    ....
    void (*SomeAction)();
    }
    @

    This is the main class that stores all data
    @class MainClass
    {
    QList<VariableItem> variableList;
    void action1();
    void action2();
    void action3();
    }
    @
    and as you guess VariableItem::SomeAction must get adress of one action from MainClass
    Using global functions solve this but i want use member methods. Maybe Qt already has solution for this cases?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Seems like a task for signal-slot mechanism.

      (Z(:^

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        Yeah
        But in some cases i need feedback.
        @class MainClass
        {
        QList<VariableItem> variableList;
        bool action1(QByteArray *, int *);
        bool action2(QByteArray *, int *);
        bool action3(QByteArray *, int *);
        }@

        edit
        Maybe something like delegates?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          broadpeak
          wrote on last edited by
          #4

          C++ "friend" mechanism can't help?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            broadpeak
            wrote on last edited by
            #5

            [quote author="qxoz" date="1350648921"]Yeah
            But in some cases i need feedback.
            @class MainClass
            {
            QList<VariableItem> variableList;
            bool action1(QByteArray *, int *);
            bool action2(QByteArray *, int *);
            bool action3(QByteArray *, int *);
            }@

            edit
            Maybe something like delegates?[/quote]

            "delegate" means in Qt world a special kind of controller.

            Signal/slot can help you beacuse the slot is a "simple" method what can return any arbitrary data.
            Maybe the signapmapper is the right choice here.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qxoz
              wrote on last edited by
              #6

              Some month ago i saw on this forum topic about creating Arraylist of functions, but i cant find it now. I think there was a solution for me.

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                qxoz
                wrote on last edited by
                #7

                Can you please show how get return value from signal
                @I = emit SomeSignal(); ?@
                and will program wait, on emit line, while binded slot is not finished?

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  You can get the return value if you invoke the signal through QMetaObject::invokeMethod. If you use the right connection type, the invokation is blocking.

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    qxoz
                    wrote on last edited by
                    #9

                    Thank you!
                    QMetaObject::invokeMethod is good solution.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved