Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connect: no such slot
QtWS25 Last Chance

Connect: no such slot

Scheduled Pinned Locked Moved General and Desktop
17 Posts 8 Posters 18.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    uzi17
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vcsala
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vcsala
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

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

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • U Offline
            U Offline
            uzi17
            wrote on last edited by
            #5

            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)

            1 Reply Last reply
            0
            • U Offline
              U Offline
              uzi17
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tomjanssens
                wrote on last edited by
                #7

                try doing a complete rebuild

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  uzi17
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #9

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

                    }
                    @

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #10

                      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.

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        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.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • U Offline
                          U Offline
                          uzi17
                          wrote on last edited by
                          #12

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

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on last edited by
                            #13

                            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?

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply
                            0
                            • B Offline
                              B Offline
                              BrawnyLad
                              wrote on last edited by
                              #14

                              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]

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                raaghuu
                                wrote on last edited by
                                #15

                                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

                                1 Reply Last reply
                                0
                                • B Offline
                                  B Offline
                                  BrawnyLad
                                  wrote on last edited by
                                  #16

                                  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?

                                  1 Reply Last reply
                                  0
                                  • K Offline
                                    K Offline
                                    koahnig
                                    wrote on last edited by
                                    #17

                                    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.

                                    Vote the answer(s) that helped you to solve your issue(s)

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved