[solved] "No such slot" error
-
Hi all. I have a problem, that I can't solve.
I have class MainWindow and I have two slots in private slots section:
@ void getData(QUrl url, QScrollArea *object);
void proccessData(QNetworkReply *pReply, QScrollArea *object);@
There are source codes of this slots:
@void MainWindow::getData(QUrl url, QScrollArea object)
{
static QNetworkAccessManager am;
QNetworkRequest request(url);
QNetworkReply reply = am.get(request);
connect(reply,SIGNAL(finished()),
this,SLOT(proccessData(reply,object)));
}
void MainWindow::proccessData(QNetworkReply *pReply, QScrollArea object)
{
QLabel label = new QLabel;
label->setText(pReply->readAll());
object->setWidget(label);
}@My app compiles without any errors, but when I "getData" calls "processData", I see that in my debug window
@Object::connect: No such slot MainWindow::proccessData(reply,object) in ..\MainWindow.cpp:166@Also I have QScrollArea without any text. Please, help me
-
Maybe the problem is the connect inside the getData slot. You could try to put it in constructor.
Hope it helps you.
Regards.
-
Your slot function is defined as
@proccessData(QNetworkReply*, QScrollArea*)@But you try to connect to, so indeed there is no such slot!
@SLOT(proccessData(reply,object))@You need to change that to:
@SLOT(proccessData(QNetworkReply*, QScrollArea*))@Also you may consider changing your function's signature to:
@proccessData(const QNetworkReply &reply const QScrollArea &area)@ -
-
[quote author="MuldeR" date="1359043460"]Your slot function is defined as
@proccessData(QNetworkReply*, QScrollArea*)@But you try to connect to
@SLOT(proccessData(reply,object)@You need to change that to:
@SLOT(proccessData(QNetworkReply*, QScrollArea*)@[/quote]thanks, I will try it
-
Edit: MuldeR beat me to item #1!
[quote author="bio120" date="1359042834"]
@
connect(reply,SIGNAL(finished()),
this,SLOT(proccessData(reply,object)));
@
[/quote]Hi bio120,
Two things to fix:
- The slot signature needs to contain the TYPES of the parameters, not the VARIABLE NAMES:
@
// Correct:
SLOT(proccessData(QNetworkReply*,QScrollArea*))
// Wrong:
SLOT(proccessData(reply,object))
@- Signals and slots must have matching parameters. Since your signal finished() has no parameters, your slot cannot have any parameters either. So, you can't connect QNetworkReply::finished() to MainWindow::proccessData(QNetworkReply*, QScrollArea*)
- The slot signature needs to contain the TYPES of the parameters, not the VARIABLE NAMES:
-
You're welcome.
To clarify point #2: You can't pass a local variable into a slot's connection. If you want to pass an argument into a slot, that argument must be emitted with the signal, e.g.
@
connect(calculator, SIGNAL(result(int)), this, SLOT(processResult(int)));
@In the above example, processResult() copies the int that was provided by result().