Connect: no such slot
-
wrote on 27 Jan 2011, 11:56 last edited by
been trying for hours and can't seem to fix this.
keep getting this error
Object::connect: No such slot Golflink::replyFinished(QNetworkReply*) in ..\Golflink\golflink.cpp:15
header
@#include <QtNetwork>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QMainWindow>namespace Ui {
class Golflink;
}class Golflink :
public QMainWindow
{
Q_OBJECTpublic:
explicit Golflink(QWidget *parent = 0);
~Golflink();public slots:
void buttonClickHandler();
void Golflink::fetch(QString url);
void Golflink::replyFinished(QNetworkReply *pReply);private:
Ui::Golflink *ui;
QNetworkAccessManager *manager;};
#endif // GOLFLINK_H
@Golflink.cpp (parts of code)
@
Golflink::Golflink(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Golflink)
{manager = new QNetworkAccessManager(this); QObject::connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*))); manager->get(QNetworkRequest(QUrl("http://www.google.com"))); ui->setupUi(this);
}
void Golflink::fetch(QString url)
{
manager->get(QNetworkRequest(QUrl(url)));ui->debugBox->setText("getting...");
}
void Golflink::replyFinished(QNetworkReply *pReply)
{
QByteArray data=pReply->readAll();
QString str(data);ui->debugBox->setText("LOADED");
}
@not sure what im missing. I'm pretty sure my code is correct by maybe my QT isn't correct?
-
wrote on 27 Jan 2011, 11:59 last edited by
I beleive "Golflink::" is not required before the slot name. Anyway it is Qt and not QT (which is the abbreviation for QuickTime).
-
wrote on 27 Jan 2011, 11:59 last edited by
I beleive "Golflink::" is not required before the slot name.
Anyway it is Qt and not QT (which is the abbreviation for QuickTime).
ADDED: Sorry there was some error in submitting, this is the reason for my not intended double posting
-
wrote on 27 Jan 2011, 12:05 last edited by
Golflink:: is in fact wrong, it must be removed.
-
wrote on 27 Jan 2011, 12:58 last edited by
i removed the Golflink in the header and cpp so its like this now
header
@
public slots:
void buttonClickHandler();
void Golflink::fetch(QString url);
void replyFinished(QNetworkReply *pReply);
@golflink.cpp
@
void replyFinished(QNetworkReply *pReply)
{
QByteArray data=pReply->readAll();
QString str(data);//ui->debugBox->setText("LOADED");
}
@
i am now getting this error
moc_golflink.obj:: error: unresolved external symbol "public: void __thiscall Golflink::replyFinished(class QNetworkReply *)" (?replyFinished@Golflink@@QAEXPAVQNetworkReply@@@Z) referenced in function "public: virtual int __thiscall Golflink::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Golflink@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
-
wrote on 27 Jan 2011, 13:18 last edited by
ok i got it working
i tried some stuff
and it screwed it up so i just went undo
to what i thought was what it originally was
compile n ran n worked.I have no idea how its working... but i still have the
Golflink:: in my header and cpp and it works :S
-
wrote on 27 Jan 2011, 13:19 last edited by
try doing a complete rebuild
-
wrote on 27 Jan 2011, 13:23 last edited by
just did and it still works. i still have the
Golflink:: -
wrote on 27 Jan 2011, 13:43 last edited by
Hi,
this should be the correct code:
header
@#include <QtNetwork>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QMainWindow>namespace Ui {
class Golflink;
}class Golflink :
public QMainWindow
{
Q_OBJECTpublic:
explicit Golflink(QWidget *parent = 0);
~Golflink();public slots:
void buttonClickHandler();
void fetch(QString url);
void replyFinished(QNetworkReply *pReply);private:
Ui::Golflink *ui;
QNetworkAccessManager *manager;};
#endif // GOLFLINK_H
@Golflink.cpp (parts of code)
@
Golflink::Golflink(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Golflink)
{manager = new QNetworkAccessManager(this); QObject::connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*))); manager->get(QNetworkRequest(QUrl("http://www.google.com"))); ui->setupUi(this);
}
void Golflink::fetch(QString url)
{
manager->get(QNetworkRequest(QUrl(url)));ui->debugBox->setText("getting...");
}
void Golflink::replyFinished(QNetworkReply *pReply)
{
QByteArray data=pReply->readAll();
QString str(data);ui->debugBox->setText("LOADED");
}
@ -
wrote on 27 Jan 2011, 13:44 last edited by
A bit of description:
you have a Class ClassA, you write:
@
class ClassA
{
public:
void foo();
void foo1();
void foo2();
};
@but not:
@
class ClassA
{
public:
void ClassA::foo();
void ClassA::foo1();
void ClassA::foo2();
};
@as you are already in the scope ClassA.
-
wrote on 27 Jan 2011, 13:45 last edited by
First:
If you constantly change your original post, no one can understand the thread later on; the answers refer to things that have vanished or are changed. This will lead to less people answering your question and may end in nobody being interested to post a solution.Second:
Get you some good C++ introduction. Leaving out the Golflink:: from method names is always needed in the .h header file, and is never what you want in the .cpp implementation file. This is C++ fundamentals, and has nothing to do with Qt.Third:
The connect function takes its signal or slot arguments (within SIGNAL() and SLOT() macros) always without the class or namespace scope arguments, only the pure method name with the argument types. -
wrote on 28 Jan 2011, 04:00 last edited by
thanks for your replies all.
I just have 1 more question. How come my connect is working when i have not defined a the 'finished' SIGNAL function?
@
QObject::connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
@shouldn't i need this in my header?
SIGNALS:
void finished(QNetworkReply *); -
wrote on 28 Jan 2011, 11:53 last edited by
Why should you? Do you implement the manager class? No! So, let's look at the API docs: Hooray! Signal finished is declared in QNetworkAccessManager, as stated "here":http://doc.qt.nokia.com/4.7/qnetworkaccessmanager.html#finished.
Of course you did read the API docs and just overlooked this, didn't you?
-
wrote on 28 Jul 2012, 21:10 last edited by
I am getting a very similar error:
Object::connect: No such slot MainWindow::reviewSetup()I inherited a large Qt project and I am new to C++. I wanted to add the reviewSetup method and so I exactly mimicked the establishment of another function, runFile().
In the header:
@
void runFile();
void reviewSetup();
...QAction *reviewSetupAction;
QAction *runFileAction;
@In the c file:
@
fileMenu->addAction(reviewSetupAction);
fileMenu->addAction(runFileAction);
...
fileToolBar->addAction(reviewSetupAction);
fileToolBar->addAction(runFileAction);
...void MainWindow::reviewSetup()
{
...
}void MainWindow::runFile()
{
...
}reviewSetupAction = new QAction(QIcon(":/images/run_file.png"),tr("Review Optimization Setup"), this);
reviewSetupAction->setShortcut(tr("Ctrl+T"));
reviewSetupAction->setStatusTip(tr("Review Optimization Setup"));
connect(reviewSetupAction, SIGNAL(triggered()),
this, SLOT(reviewSetup()));runFileAction = new QAction(QIcon(":/images/run_file.png"),tr("Save and Run NEPTUNE data file"),this); runFileAction->setShortcut(tr("Ctrl+R")); runFileAction->setStatusTip(tr("Save and Run NEPTUNE data file")); connect(runFileAction, SIGNAL(triggered()), this, SLOT(runFile()));
@
Thanks
[edit, code tags added, koahnig]
-
wrote on 29 Jul 2012, 08:00 last edited by
in the header file, the slots need to be declared(like the public, private or protected parts)
@
void runFile();
public slots: //... or private slots:
void reviewSetup();
@P.S. you should put '@' just before your code starts and just after it ends to make it look good
-
wrote on 30 Jul 2012, 20:44 last edited by
Thanks for your reply, raaghuu!
I should have made my code snips more clear: The snippets shown in lines 1 and 2 are part of a block that begins
private slots:Secondly, I'm not sure I understand your P.S. Are you saying I should use the ampersands in my forum postings?
-
wrote on 31 Jul 2012, 07:56 last edited by
Hi BrawnyLad
raaghuu meant the code wrappings '@', please "check out the forum help":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01
I had updated your post and introduced them already.