0

I'm new in Qt... I'm creating N buttons based on a JSON file. And I need to run a function/slot when a button is clicked and I need to know which buttton was pressed. I tried:

QObject::connect(button, &QToolButton::clicked, this, &base::show_brands(json, type));

show_brands(json, type) is a function/slot... but I can't send args like this... How can I sent args to my function/slot? Or how can I run a function when a button is clicked?

vitor13almeida
  • 139
  • 1
  • 11
  • 1
    1) to pass arguments into a slot you have to pass them through your signal. 2) or see this post [link](http://stackoverflow.com/questions/5153157/passing-an-argument-to-a-slot) – Bob Oct 18 '16 at 15:46
  • I tried signals but it's not working... Maybe I'm doing it wrong. I've searched online and I can check the sender... How do I do it? – vitor13almeida Oct 18 '16 at 16:21

1 Answers1

0

You want to use QSignalMapper;

http://doc.qt.io/qt-5/qsignalmapper.html#details

This lets you send signals from a collection of objects to a single method which can identify the source object.

john elemans
  • 2,578
  • 2
  • 15
  • 26