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. &Action and &MayApp::Slot() : How to pass arguments

&Action and &MayApp::Slot() : How to pass arguments

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 1.1k Views 2 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.
  • Christian EhrlicherC Christian Ehrlicher

    @ademmler said in &Action and &MayApp::Slot() : How to pass arguments:

    How can I pass "pos" or how can I change the trigger to match ...

    Use a lambda

    ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by
    #3

    @Christian-Ehrlicher

    Hi Christian- like this? The same error.

    connect(action_SetColor, &QAction::triggered,
                this, // <- control object
                [this](QPoint& pos)
                {SpectraProof::slot_SetColor(pos);});
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hi,

      First some questions:

      • Why are you re-connecting that action each time a contextual menu is created ?
      • How is this position related to the slot ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      ademmlerA 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        First some questions:

        • Why are you re-connecting that action each time a contextual menu is created ?
        • How is this position related to the slot ?
        ademmlerA Offline
        ademmlerA Offline
        ademmler
        wrote on last edited by
        #5

        @SGaist

        1. Its linked to an list widget item.
        2. In another thread this was meant to be the only option ;-)
          Ofcourese I can put it also to app start section ...
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #6
          1. but you are just reconnecting the exact same action again and again.
          2. It's not really clear.

          Can you maybe describe what you want to achieve between the contextual menu and slot_SetColor ?

          From pure guess, your menu seems to be some sort of color picker, if so, I fail to see what the position of the right click comes into play with that slot.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          ademmlerA 1 Reply Last reply
          0
          • SGaistS SGaist
            1. but you are just reconnecting the exact same action again and again.
            2. It's not really clear.

            Can you maybe describe what you want to achieve between the contextual menu and slot_SetColor ?

            From pure guess, your menu seems to be some sort of color picker, if so, I fail to see what the position of the right click comes into play with that slot.

            ademmlerA Offline
            ademmlerA Offline
            ademmler
            wrote on last edited by ademmler
            #7

            @SGaist Ofcourse I can:

            In my main window I have a listWidget. This has a list of colors.
            I want to do a right click on those items -> this opens a list of possible commands:

            At app start I define:

            action_SetColor = new QAction(tr("Set color"), this);
            action_SetOpaque = new QAction(tr("Set opaque"), this);
            action_AddColor = new QAction(tr("Set opaque"), this);
                listWidgetMenu=new QMenu(this);
                listWidgetMenu->addAction(action_SetColor);
                listWidgetMenu->addAction(action_SetOpaque);
                listWidgetMenu->addAction(action_AddColor);
            

            I have activated contextMenue in QtCReator for this listWwidget and I have set a slot:

            void MyApp::on_listWidget_customContextMenuRequested(const QPoint &pos)
            {
            //This let the listwidet with commands appear
            listWidgetMenu->popup(ui->listWidget->viewport()->mapToGlobal(pos));

            And now I need to start the "action" chosen from this list passing the position ...
            I need the position for the following action to know which list item has been clicked.
            }

            1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @ademmler said in &Action and &MayApp::Slot() : How to pass arguments:

              How can I pass "pos" or how can I change the trigger to match ...

              Use a lambda

              ademmlerA Offline
              ademmlerA Offline
              ademmler
              wrote on last edited by
              #8

              @Christian-Ehrlicher

              can you tell me, what's wrong with my lamda - please?

              jsulmJ 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #9

                Then let's simplify this: just connect your action's triggered signal after you create them.

                There's no need for that convoluted logic you are trying to implement with the right click position. In the slot you can request the current selected item and apply your code on it.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                ademmlerA 2 Replies Last reply
                0
                • SGaistS SGaist

                  Then let's simplify this: just connect your action's triggered signal after you create them.

                  There's no need for that convoluted logic you are trying to implement with the right click position. In the slot you can request the current selected item and apply your code on it.

                  ademmlerA Offline
                  ademmlerA Offline
                  ademmler
                  wrote on last edited by
                  #10

                  @SGaist Sounds good - hence I was miss leaded ... I try this and let you know. thx in advance

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Then let's simplify this: just connect your action's triggered signal after you create them.

                    There's no need for that convoluted logic you are trying to implement with the right click position. In the slot you can request the current selected item and apply your code on it.

                    ademmlerA Offline
                    ademmlerA Offline
                    ademmler
                    wrote on last edited by
                    #11

                    @SGaist thx for simplifying my life ;-)

                    1 Reply Last reply
                    0
                    • ademmlerA ademmler

                      @Christian-Ehrlicher

                      can you tell me, what's wrong with my lamda - please?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @ademmler said in &Action and &MayApp::Slot() : How to pass arguments:

                      can you tell me, what's wrong with my lamda - please?

                      Capturing parameters in lambdas does not work like you're doing:

                      connect(action_SetColor, &QAction::triggered,
                                  this, // <- control object
                                  [pos, this]()
                                  {SpectraProof::slot_SetColor(pos);});
                      

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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