0

Just started out with Qt (and C++ for that matter), and haven't got really used to the SIGNAL/SLOT system.

I have simplified my code down to this:

int main()
{
int number = 1;
int * numptr;
numptr = number;
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(start(numptr);
}

I have a button called 'pushButton' that when pushed, I want it to start a "start" function that takes an integer pointer as an argument.

int start(int * number)
{
// Do something with the number
}

But this doesn't seem to work. How can I call function start and pass the number pointer as a parameter when the pushbutton is clicked?

ddybing
  • 77
  • 1
  • 8

1 Answers1

2

The easiest way will be to connect to a lambda function and capture the numptr:

connect(ui.pushButton, &QPushButton::clicked, [numptr](){
    // Do something with the number
});
OwlCodR
  • 173
  • 2
  • 9
JarMan
  • 7,589
  • 1
  • 10
  • 25
  • True. I didn't notice the OP was calling it from main. Notice that the OP also uses `this` in their own code. I'll remove it from mine. – JarMan Aug 03 '21 at 20:59