Connect: no such slot



  • 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_OBJECT

    public:
    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?



  • I beleive "Golflink::" is not required before the slot name. Anyway it is Qt and not QT (which is the abbreviation for QuickTime).



  • 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



  • Golflink:: is in fact wrong, it must be removed.



  • 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)



  • 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



  • try doing a complete rebuild



  • just did and it still works. i still have the
    Golflink::



  • 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_OBJECT

    public:
    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");
    

    }
    @



  • 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.



  • 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.



  • 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 *);



  • 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?



  • 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&#40;&#41;&#41;);
    

    @

    Thanks

    [edit, code tags added, koahnig]



  • 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



  • 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?


  • Moderators

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.