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. Can I "connect" using QAction as sender ?
Forum Updated to NodeBB v4.3 + New Features

Can I "connect" using QAction as sender ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 342 Views 3 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by Anonymous_Banned275
    #1

    EDIT
    I got the answer here

    https://forum.qt.io/topic/131708/multiple-qaction-and-using-sender-to-get-which-got-selected/2

    Very basic question, and if the answer is no , can you suggest alternative to "connect" using QAction ?

    The attached TEST C++ code works with sender QMenu and gets me ton of error messages when the sender is QAction,

                            connect(subMenu[index_sub] , &QMenu::triggered, this ,
                                    [=]() { this->processAction(index_sub,index) ;});
    
                            // connect to main submenu
    connect(TEMP_[index] ,  &QMenu::triggered, this ,[=]() { this->processAction(index_sub,index) ;});
    
    Pl45m4P 1 Reply Last reply
    0
    • A Anonymous_Banned275

      EDIT
      I got the answer here

      https://forum.qt.io/topic/131708/multiple-qaction-and-using-sender-to-get-which-got-selected/2

      Very basic question, and if the answer is no , can you suggest alternative to "connect" using QAction ?

      The attached TEST C++ code works with sender QMenu and gets me ton of error messages when the sender is QAction,

                              connect(subMenu[index_sub] , &QMenu::triggered, this ,
                                      [=]() { this->processAction(index_sub,index) ;});
      
                              // connect to main submenu
      connect(TEMP_[index] ,  &QMenu::triggered, this ,[=]() { this->processAction(index_sub,index) ;});
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @AnneRanch

      If the signal is not there in QAction, how would you be able to use it?! Of course it does't work, if you use random signals and try to use them with other classes...

      @AnneRanch said in Can I "connect" using QAction as sender ?:

      connect(TEMP_[index] , &QMenu::triggered,

      And if TEMP_[index] is a QAction, you need to change it to &QAction::triggered


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      A Axel SpoerlA 2 Replies Last reply
      1
      • Pl45m4P Pl45m4

        @AnneRanch

        If the signal is not there in QAction, how would you be able to use it?! Of course it does't work, if you use random signals and try to use them with other classes...

        @AnneRanch said in Can I "connect" using QAction as sender ?:

        connect(TEMP_[index] , &QMenu::triggered,

        And if TEMP_[index] is a QAction, you need to change it to &QAction::triggered

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @Pl45m4 Thanks, just found my error.

        1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @AnneRanch

          If the signal is not there in QAction, how would you be able to use it?! Of course it does't work, if you use random signals and try to use them with other classes...

          @AnneRanch said in Can I "connect" using QAction as sender ?:

          connect(TEMP_[index] , &QMenu::triggered,

          And if TEMP_[index] is a QAction, you need to change it to &QAction::triggered

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          @AnneRanch

          @Chris-Kawa explained here, how actions are added to a menu.

          If I remember your code correctly from previous posts, TEMP_is an array of QMenu.
          So the connect statement connects to a menu, which works only with signals of QMenuor one of its base classes. QAction isn't such a base class of QMenu, which is the reason for your compiler errors.

          It's not possible to suggest a working alternative, because we don't know where you store the pointer to the QActionreturned by addAction("yourText").
          Let's assume it is stored in QAction *tempAction.
          In that case the following would work:

          connect(tempAction, &QAction::triggered, this, [=]() {this->processAction(index_sub, index); });
          

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          1

          • Login

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