passing arguments in SLOT
Hi, I'm having problem passing arguments in SLOT:
Code:
private slot:
void connectToHost
(QString, quint32
);
and I'm calling it like this:
Code:
connect(connectButton, SIGNAL(clicked()), this, SLOT(connectToHost(host, port)));
while the connectToHost is:
Code:
void MainWindow
::connectToHost(QString host, quint32 port
) { /* create and connect to the socket */
socket
->connectToHost
(host, port,
QIODevice::ReadOnly);
}
Problem is:
Object::connect: No such slot MainWindow::connectToHost(host,port)
Re: passing arguments in SLOT
Hi,
isn't it "private slots: ?
Re: passing arguments in SLOT
Yes it is...I make a mistake typing....
I have slots in my code.
Re: passing arguments in SLOT
You don't call a slot with connect.
You create a connection to between a signal and a slot with connect.
Every time that signal is emitted (with its arguments) the slots is called with those.
If you want to call a 'slot', just do it. It is a regular function.
When connecting you must not use names of some variables, but types:
Code:
// does not quite work
connect(connectButton,
SIGNAL(clicked
()),
this,
SLOT(connectToHost
(QString, quint32
)));
This does not work either, as the slot's arguments must be those (or less) of the signal.
clicked() has no arguments, so neither can the slot you connect to.
Code:
// perhaps in the constructor:
connect(connectButton, SIGNAL(clicked()), this, SLOT(doConnect()));
MainWindow::doConnect()
{
connectToHost(host, port);
}
where host and port would be members of MainWindow, and doConnect a slot in MainWindow.
connectToHost can be a slot, but does not have to, since you're only connecting to doConnect() here.
HTH
PS: Do read the excellent Qt docs and tutorials on the subject!