Question

I want to use a QMap that I have previously created to be used inside a slot. I've tried following this but it still did not work (I think I am just doing something stupid). Here is the code I am using.

Constructor:

QMap <int, QList<int> > tiles;
connect(ui->lineEdit, SIGNAL(editingFinished()), this, SLOT(someSlot()));

Now, whenever I send the signal editingFinished, I want someSlot to check if the value is in the QMap and proceed with the various conditions if it is. Problem is, how do I pass my QMap to a slot? Qt does not seem to allow slots with parameters.

Was it helpful?

Solution

A slot is just a function called by Qt. There is magic in how it's called but it's just a function. Arguments are passed into the signal (just like a regular function) and Qt eventually passes that argument (or more likely a copy of that argument) to the recipient slot. There is logic in Qt where you don't have to pass as many arguments to the slot as you did the signal when defining the connection but that's not for this discussion.

You cannot pass arguments by name in a connection like this.

You can either have your tiles object be a member variable of your class that implements someSlot() or you will have to pass tiles to a signal that is connected to someSlot(const QMap >&)

My recommendation is to make tiles a member variable, not a stack variable

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top