Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create virtual SLOT for action
Forum Updated to NodeBB v4.3 + New Features

How to create virtual SLOT for action

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.6k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    betmens
    wrote on last edited by
    #1

    Is it possible to send fonction for SLOT?
    @//get actions
    void get_actions(QWidget *widget, QStringList list, ??? slot){
    foreach (QString t, list){
    QAction *a = new QAction("&"+t, widget);
    a->setObjectName("act_"+t);
    widget->addAction(a);
    connect(a, SIGNAL(triggered()), ???, SLOT(slot));
    }
    }
    void Project::do_something_1(){...}
    void Project::do_something_2(){...}
    ...
    get_actions(ui->menu_actions_1, QStrinList()<<"name_1"<<"name_2", do_something_1());
    ...
    get_actions(ui->menu_actions_2, QStrinList()<<"name_3"<<"name_4", do_something_2());@

    Thanks

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rahul Das
      wrote on last edited by
      #2

      What exactly are you trying to do ? Slot can be treated as any other c++ functions. Looks like you might want to look at [[Doc:QSignalMapper]]


      Declaration of (Platform) independence.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RaubTieR
        wrote on last edited by
        #3

        As we look into the qobject.h file for the "connect" declaration, it becomes clear what to do.
        @bool connect(const QObject *sender, const char *signal, const char *member // , ...@

        I've simplified the declaration since it was big. But here we see that both SIGNAL and SLOT are const char pointer. Hence your code of choice is:
        @//get actions
        void get_actions(QWidget *widget, QStringList list, const char *slot){
        foreach (QString t, list){
        QAction *a = new QAction("&"+t, widget);
        a->setObjectName("act_"+t);
        widget->addAction(a);
        connect(a, SIGNAL(triggered()), slot);
        }
        }
        void Project::do_something_1(){...}
        void Project::do_something_2(){...}
        ...
        get_actions( ui->menu_actions_1, QStrinList()<<"name_1"<<"name_2", SLOT(do_something_1()) );
        ...
        get_actions( ui->menu_actions_2, QStrinList()<<"name_3"<<"name_4", SLOT(do_something_2()) );@

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

          Thanks RaubTieR.
          Works great.

          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