0

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.

Community
  • 1
  • 1
pureooze
  • 156
  • 2
  • 11
  • How would the slot know what map to use? – cppguy Jan 23 '13 at 23:19
  • Do you mean doing something like someSlot(tiles)? Because that didnt work for me. **error: implicit instantiation of undefined template 'QMap >' case 2: _t->someSlot((*reinterpret_cast< 'QMap >(*)>(_a[1]))); break;** ^ – pureooze Jan 23 '13 at 23:21

1 Answers1

1

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

cppguy
  • 3,611
  • 2
  • 21
  • 36
  • A member variable is one that is declared in the class correct? Because when I tried to do the declaration `QMap > tiles;` I got an error "field 'tiles' has incomplete type". Sorry if its a silly mistake but what does it mean? – pureooze Jan 24 '13 at 01:24
  • Oh man I was being so dumb. Ignore that. Anyways I have it working now, thanks. – pureooze Jan 24 '13 at 01:52